Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nkotb;
- import java.util.Scanner;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class CustomerOverview {
- String url = "jdbc:mysql://localhost:3306/nkotb";
- String user = "root";
- String password = "";
- PreparedStatement stmt = null;
- ResultSet rs = null;
- Connection conn = null;
- Scanner userInput = new Scanner(System.in);
- public void CustomerOverview() {
- System.out.println("Enter your ID.");
- String Id = userInput.next();
- try {
- conn = DriverManager.getConnection(url, user, password);
- stmt = conn.prepareStatement("SELECT * FROM Customers WHERE Name ='" + Id + "' ; ");
- rs = stmt.executeQuery();
- while (rs.next()) {
- String dbLoan = rs.getString("Loan");
- String dbSavings = rs.getString("Savings");
- System.out.println("Loans & Savings:");
- System.out.println("Loan: " + dbLoan);
- System.out.println("Savings: " + dbSavings);
- }
- } catch (SQLException exc) {
- System.out.println(exc.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment