I have to connect a database to my codes to check a pin code. I have managed to make it but I'm having some problem to make the else part of the if statement to work. I think its the query part which is causing the problem as when I change the if..else statement it works perfectly.
If there is any other way to write this query to get the same result please let me know
thank you
public void getOperation() {
{
Connection conn = null;
String query = "SELECT pin FROM customerdetails WHERE pin='"+Pin+"'";
Statement stmt = null;
try {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/customerdb", "user","@1234@");
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String password = rs.getString("pin");
if (Pin.equals(password)) {
PinCheck = "Pin OK";
} else
{
PinCheck = "Invalid Pin";
}
}
} catch (SQLException e) {
System.err.println(e);
} finally {
if (stmt != null) {
}
if (conn != null ) {
//conn.close();
}
}
}