I'm working a login sample for my Enrollment System. While doing some research grab some codes that I see on the internet. Which I will login in the fields of Username & Password. Where I encounter error using SQL. Any help, tips will appreciate!
ERROR
Error message: Syntax error: Encountered "," at line 1, column 42.
Error code: -1
SQL State: 42X01
This is where the compiler pointing the error at line 1, Column 42. I used Windows Listener for the which can I used for system closing.
Window Listener Code
//Window Listener
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}//window Closing
});
Code This is where I login. When I finish filling up the username and password textfields and hit the login button Which where I encounter the error.
loginButton.addActionListener(new ActionListener (){
public void actionPerformed(ActionEvent e){
String inputUsername = usernameTextField.getText().trim();
String inputPassword = String.valueOf(passwordPasswordField.getText());
String inputUserType = listUser.getSelectedItem().toString();
if(inputUsername.isEmpty() && inputPassword.isEmpty()){
JOptionPane.showMessageDialog(null, "Please fill up!");
}
else if(inputUsername.isEmpty()){
JOptionPane.showMessageDialog(null, "Please enter your username");
}
else if(inputPassword.isEmpty()){
JOptionPane.showMessageDialog(null, "Please enter your password");
}
else{
String myQuery = "SELECT * FROM USERTYPE WHERE USERNAME = ?, PASSWORD = ?";
try(Connection myConnection = DBUtil.getConnection(DBType.JDBC);
PreparedStatement myPs = myConnection.prepareStatement(myQuery);
ResultSet myResultSet = myPs.executeQuery()){
while(myResultSet.next())
myPs.setString(1, inputUsername);
myPs.setString(2, inputPassword);
myPs.executeUpdate();
JOptionPane.showMessageDialog(null, "Succesfuly Inserted!");
//end of else
}//end of try
catch(SQLException ex) {
DBUtil.processException(ex);
}//end of catch
}//end of else
}//end of action performed
});//end of action listener`
DBUtil as my connection and exception This is where I set aside my connection and exception which where throws the error
private static final String dbUrl = "jdbc:derby://localhost:1527/Info";
private static final String username = "john";
private static final String pass = "john";
//Argument for DBType
public static Connection getConnection(DBType dbType) throws SQLException{
return DriverManager.getConnection(dbUrl,username,pass);
}
public static void processException(SQLException e){
System.err.println("Error message: "+e.getMessage());
System.err.println("Error code: "+e.getErrorCode());
System.err.println("SQL State: "+e.getSQLState());
}
WHERE USERNAME = ?, PASSWORD = ?- in which manual did you find that syntax? It should beWHERE USERNAME = ? and PASSWORD = ?.