Following is the code to display the tuples which has the username and password matching the strings
String usr = tf1.getText();
String pwd = tf2.getText();
System.out.println("Username is " + usr + " Password is " + pwd);
String sql = "select * from student where first = '"+usr+"' and last = '"+pwd+"';";
System.out.println("SQL is " + sql);
try {
rset = stmt.executeQuery(sql);
if(rset.next()){
JOptionPane.showMessageDialog(null, " Login Successfull...");
}
}
catch(SQLException e){
JOptionPane.showMessageDialog(null, e);
}
// TODO add your handling code here:
}
Is there any mistake in framing the query here.pPlease check the string 'sql'. The null pointer exception is at the following statement.
rset = stmt.executeQuery(sql);
This sql string is not null because, when I print it on console it shows me
select * from student where first = 'rohit' and last = 'rocks';
So, its not null at the runtime. If sql is not null then why am I getting the NullPointer Exception?