lundi 1 décembre 2014

Comparing MySQL DB object with a String in Java


Vote count:

0




I'm working on a program to manage students in a DB, and I'm working on the part where students can sign in, but for some reason I can never get the if statement to be true. I'm thinking it has something to do with the value I'm getting from the database being an object as opposed to a String. I've tried casting it to String but I get an error, is there anyway I can compare these two values? My code is below so you can take a look. I know there are other questions like this, but I've not been able to get any of their solutions to work. Thanks so much in advance.



public void actionPerformed(ActionEvent e)
{
//int i;
//String name;

if(e.getSource()==logInButton)
{
String name="";
String password="";

name=inputField.getText();
password=inputField2.getText();




try {
connection = DriverManager.getConnection(connectionString, username, pass);
PreparedStatement statement = (PreparedStatement) connection.prepareStatement("SELECT * FROM students");
data = statement.executeQuery();
while(data.next()){
//login = data.getObject("student_id").equals(name) && data.getObject("password").equals(password);
if(data.getObject("student_id").equals(name) && data.getObject("password").equals(password))
{
System.out.println("login = true");
logInPanel.setVisible(false);
postLogInPanel.setVisible(true);
}

}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

}


asked 1 min ago







Comparing MySQL DB object with a String in Java

Aucun commentaire:

Enregistrer un commentaire