I'm new to java and I'm making a ATM/bank app as small project to enhance my skills. I'm trying to see if it is possible to validate the Jtextfield to MySQL database. I have learnt how to validate inputted text in the console i.e.
Enter name : BOB , Sorry this doesn't match the database.
However, when trying to do similar for Jtextfield it won't work. I'm also trying to do OOP so I have a class for MySQL userDatabase and a separate class for Controller/Main page.
I have uploaded the scanner method I mentioned before as my textfield code is shambles MySQL class (p.s sorry for messy code) `public class UsersDatabase {
public static void main(String[] args) throws SQLException {
String url = "jdbc:mysql://localhost:3306/atm";
String uname = "root";
String password = "root";
//scans input
Scanner sc = new Scanner(System.in);
//captures string
String name = sc.next();
//String communicates with db
String query = "SELECT * FROM AtmUsers WHERE First_Name = '" + name + "'" ;
//check if it works
try {
Class.forName("com.mysql.cj.jdbc.Driver");
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
//test
try {
Connection con = DriverManager.getConnection(url, uname, password);
//communicate with db
Statement statement = con.createStatement();
ResultSet rs = statement.executeQuery(query);
//check whether we received anything
if (rs.next())
System.out.println("Success");
else
System.out.println("Failure!");
}catch (SQLException e){
e.printStackTrace();
}
}
}`
Main class
public String userInput;
Users users = new Users();
UsersDatabase usersDatabase = new UsersDatabase();
public void check(ActionEvent event) throws IOException {
userInput = number.getText();
String userPinCheck = pin.getText();
// check account number
if (usersDatabase.equals()) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error Dialog");
alert.setHeaderText(null);
alert.setContentText("Please make sure that your account exists");
alert.showAndWait();
}
so i tried multiple stuff in the userDatabase.equals() but as I said I cant figure it out so any help/advice would be great. Thank You!!