Reputation: 3
please i am trying to check if an entry exists in an sqlite database column. and i am using java. here is what my code looks like
String name =JTextField.getText();
String sql0 = "select * from Objects where Description like " + name;
pStmt = conn.prepareStatement(sql0);
rs = pStmt.executeQuery();
if (rs.next()) {//if there is such entry...
System.out.println("there is an entry");
} else {//no such entry add the asset normally...
System.out.println("there is no such entry");
}
the code is just a test code for testing my sqlite query... name is the the entry to search for in the Description Column. whenever i run this i get an error saying no such column as the value i have stored as name. please i really need help on this thanks.
Upvotes: 0
Views: 1423
Reputation: 3389
I am not really familiar with sql in java but propably you need to use quotes to escape the string
Change
String sql0 = "select * from Objects where Description like " + name;
To
String sql0 = "select * from Objects where Description like '" + name + "'";
Another way is to use prepared staments
Upvotes: 2