Hey guys,
Howdy!
Well I was trying out a simple UI with
Java which retrives values from MySQL database. I'm using Netbeans Version 6.1 & Linux Platform. The whole idea is pretty simple! I use a list, button and 4 text boxes. The list contains names of friends table and on clicking the button I display values in those textboxes. The database connection works perfect as I could see the names in the list(names from 'name' column in friends table). But when I click the button I get these following errors:
SQLException: Unknown column 'x' in 'where clause'
SQLState: 42S22
ErrorCode: 1054
This is the piece of code where the above mentioned action takes place:
getNameButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
//connectToDB();
Statement statement = connec.createStatement();
ResultSet rs = statement.executeQuery("select * from friends where name = " + detailsList.getSelectedValue());
if(rs.next())
{
nameText.setText(rs.getString("name"));
degreeText.setText(rs.getString("degree"));
//remarksText.setText(rs.getString("Remarks"));
initialsText.setText(rs.getString("initials"));
marksText.setText(rs.getString("marks"));
}
//rs.close();
}
catch(SQLException ee)
{
displaySQLErrors(ee);
}
}
}
What do I do to overcome this issue?