[SOLVED]help please! The resultset seems return the same, i need to refresh it
Hi guys, help me please, the resultset seems return the same as the first resultset. This is a log in form that is connected to a mysql database.
Database contained(username field): 1,2,3,4...10
When I entered a number within 1 to 10 it should output "Found"
When I entered a number that is not within 1 to 10 it should output "Not Found"
Heres my code:
Code:
//code for package database
public void setLogInMember(String cmboxSql){
String mySql = cmboxSql;
setLogInMemberList(mySql);
}
private void setLogInMemberList(String mySql){
try{
statement = con.createStatement();
resultSet = statement.executeQuery(mySql);
if(resultSet!=null){
while(resultSet.next()){
username = resultSet.getString(1);//return the username if there is
}
}
}catch(SQLException sqlex){
username = "";
}
finally{
try {
resultSet.close();
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public String getUsername(){
return username;
}
private Statement statement;
ResultSet resultSet;
private String username;
private String password;
//code for package gui
btnEnter.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
String username = "SELECT * FROM cooperativeDb WHERE aMeterNo = " +txtUserName.getText();
try{
dbLogMem.setLogInMember(username);
if(dbLogMem.getUsername().equals("")){
System.out.println("not found");
}else{
System.out.println("found");
}
}catch(Exception e1){System.out.println("not found");}
}
}
);
When I entered 5 at first run: "Found"
When I entered another number this time I entered 15: "Found" //this is should "Not Found"
I stop run program.
When I entered 15 at first run: "Not Found"
When I entered another number this time I entered 1: "Not Found" //this is should "Found"
I stop run program.
Same problem as before, it always display the result of the first entered username...
I'd already use PreparedStatement and Statement
Please help me guys whats wrong with my code