Why do you think this function gives me always null?? Using another login program, which has the same code structure, it works greatly. My DBURL is jdbc:mysql://localhost:8889/database
public String retrieveUserPassword(String userName, String password) {
String query = "SELECT UserPassword FROM Access where UserName='"+userName+"'";
String dbresult=null; //this might be the problem, but I must define it
try {
Class.forName("com.mysql.jdbc.Driver");
}catch (ClassNotFoundException ex1) {
System.out.println("Driver could not be loaded: " + ex1);
Logger.getLogger(DatabaseModel.class.getName()).log(Level.SEVERE, null, ex1);
}
try {
//These are private variables declared at the top of the class
//and used by various functions
con = DriverManager.getConnection(DatabaseURL, userName, password);
st = con.createStatement();
rs = st.executeQuery(query);
if(rs.next()){
dbresult= rs.getString(3);
}
}catch (SQLException e) {
e.printStackTrace();
}
return dbresult;
}
The Access table is composed of three columns: UserID, UserName, UserPassword
if(rs.next())is true.