Reputation: 25
I need help with the below error. Below is the method, retrievePassword(). I programmed it so that when the Clickid is called, I can retrieve all other datas too.
public boolean retrievePassword() {
// declare local variables
boolean success = false;
ResultSet rs = null;
DBController db = new DBController();
// step 1 of using DBController, passing data source name setup during last practical
db.setUp("myDatabase");
// declare the SQL
String dbQuery = "SELECT Clickid FROM PROFILE WHERE Clickid = '" + clickId + "'" ;
// step 2 of using DBCcontroller, for retrieve SQL use readRequest method
rs = db.readRequest(dbQuery);
try{
if (rs.next()){
firstName = rs.getString("Firstname");
lastName = rs.getString("LastName");
password = rs.getString("Password");
email = rs.getString("Email");
success = true;
}
}
catch (Exception e) {
e.printStackTrace();
}
db.terminate();
return success;
}
I have checked and all the column names are correct. I think the problem lies with either the above method or the instantiation below
String first = jTextFieldFirst.getText();
String email = jTextFieldEmail.getText();
Profile p2 = new Profile(jTextFieldId.getText());
p2.retrievePassword();
String firstName = p2.getFirstName();
String email2 = p2.getEmail();
if(email == email2 && first == firstName)
JOptionPane.showMessageDialog(null, "Your Password is "+p2.getPassword(),
"Retrieve Password",JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, "Some information you entered is incorrect", "Retrieve Password",JOptionPane.INFORMATION_MESSAGE);
When I compiled and typed in the respective fields, the error "Column not found" keeps appearing. I have ensured that the column names and data are correct but I have more columns that I didnt include in the retrievePassword() method. I am sure it is either of this 2 methods that seems to be the problem but I cant seems to solve it no matter how I do it. Will some kind soul help me? Please?
Upvotes: 0
Views: 8281
Reputation: 25
Hey all, I did what you all said and selected all the columns and it was a success. But when I implement the method below
String first = jTextFieldFirst.getText();
String email = jTextFieldEmail.getText();
Profile p2 = new Profile(jTextFieldId.getText());
p2.retrievePassword();
String firstName = p2.getFirstName();
String email2 = p2.getEmail();
if(email == email2 && first == firstName)
JOptionPane.showMessageDialog(null, "Your Password is "+p2.getPassword(),
"Retrieve Password",JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, "Some information you entered is incorrect", "Retrieve Password",JOptionPane.INFORMATION_MESSAGE);
It keeps showing the jOptionPane from the else loop. What i need is actually to get the if loop out when I typed in the correct field =(. Thanks for all of your help =)
Upvotes: 0
Reputation: 457
you select only the clickid column. try select * from profile or better use a column list.
Upvotes: 1
Reputation: 6331
Looks like your query only selects the ClickId field but then in your result you're trying to obtain other fields. Use SELECT * or SELECT with the fields you need instead.
Upvotes: 5
Reputation: 7096
That's correct, you need to retrieve FirstName, LastName, Email, and Password in your select query if you're going to be using them from the result set.
Upvotes: 1