In a JSP I'm using JDBC and I just need to build a simple SQL statement that will selecct data that matches String data input from user on HTML form with varchar field in database. String sql = "SELECT * FROM login where logid =" + id ; The code above gives error that the value of id is not a column . I tried putting quotes, etc around id but nothing works...
You were right when you tried to add quotes to the query, cause this is the fault. The only thing you have to be look for is that some databases only can handle single quotes. Also you have to be careful with the syntax when you use double quotes. double quotes(you have to masquerade them): String sql = "SELECT * FROM login where logid =\"" + id + "\"" ; single quotes: String sql = "SELECT * FROM login where logid ='" + id +"'";
Joined: Feb 12, 2001
Thanks, I think I see now the problem I had. There should be 3 quotes on the right side. I think I missed that before.