Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple SQL statement

 
frank davis
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 +"'";
 
frank davis
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic