File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes how to use 'where' clause Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "how to use Watch "how to use New topic

how to use 'where' clause

gaurav chhabra
Ranch Hand

Joined: Jul 24, 2004
Posts: 109
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
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
try to remove ' '

SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1141

In my opinion, better to use a "PreparedStatement".
[NOTE: Below code is uncompiled and untested.]

Good Luck,
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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.
I agree. Here's the link:
subject: how to use 'where' clause
It's not a secret anymore!