Guest User

Untitled

a guest
Mar 16th, 2016
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. package nkotb;
  2.  
  3. import java.util.Scanner;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9.  
  10. public class CustomerOverview {
  11.  
  12. String url = "jdbc:mysql://localhost:3306/nkotb";
  13. String user = "root";
  14. String password = "";
  15. PreparedStatement stmt = null;
  16. ResultSet rs = null;
  17. Connection conn = null;
  18. Scanner userInput = new Scanner(System.in);
  19.  
  20. public void CustomerOverview() {
  21.  
  22. System.out.println("Enter your ID.");
  23. String Id = userInput.next();
  24.  
  25. try {
  26. conn = DriverManager.getConnection(url, user, password);
  27. stmt = conn.prepareStatement("SELECT * FROM Customers WHERE Name ='" + Id + "' ; ");
  28. rs = stmt.executeQuery();
  29.  
  30. while (rs.next()) {
  31. String dbLoan = rs.getString("Loan");
  32. String dbSavings = rs.getString("Savings");
  33.  
  34. System.out.println("Loans & Savings:");
  35. System.out.println("Loan: " + dbLoan);
  36. System.out.println("Savings: " + dbSavings);
  37. }
  38.  
  39. } catch (SQLException exc) {
  40. System.out.println(exc.getMessage());
  41. }
  42. }
  43.  
  44. }
Add Comment
Please, Sign In to add comment