For school I'm working on a program that connects to a MySQL database and perform queries such as an ATM machine might.
So far I've made a simple program where I've been putting my connection code in the submit button, but now I need to support many different buttons for balance query, withdrawal, etc.
For my initial screen where the user enters their login and PIN I have the following code, but I'm kind of lost as to how I can do these queries under other buttons with the variables I have in this button:
private void bSubmitActionPerformed(java.awt.event.ActionEvent evt) {
String login = jLogin.getText();
String pin = jPin.getText();
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/bankaccount", "root", "password");
Statement st = (Statement) con.createStatement();
PreparedStatement ps;
String sqlCommand;
ResultSet rs;
sqlCommand = "SELECT * FROM accounts WHERE loginID= '" + login + "' AND pin='" + pin + "'";
rs = st.executeQuery(sqlCommand);
if (rs.next()) {
do {
card2.setVisible(true);
card1.setVisible(false);
} while (rs.next());
} else {
jWarning.setText("please try again");
}
} catch (Exception e) {
}
}