• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use 'where' clause

 
gaurav chhabra
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir i m using MS ACCESS and writing the query...

String query = "select * from general_information where id = '" + id5+ "'";

id is "int" and id5 is also an "int"....

id5 is a variable....of int type
but if i write the above query then it is giving no result but if i m writing ...

String query = "select * from general_information where id = 10 ";

then it is working........

please tell me for the query........
thank you
gaurav
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to remove ' '
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav,
In my opinion, better to use a "PreparedStatement".
[NOTE: Below code is uncompiled and untested.]

Good Luck,
Avi.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, integer/number literals should not be in single quotes. Better use PreparedStatement, as said earlier.

By the way, why you kept "id5" in single quotes and "10" without quote, both are integers/numbers though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic