aspose file tools*
The moose likes JDBC and the fly likes Simple SQL question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Simple SQL question" Watch "Simple SQL question" New topic
Author

Simple SQL question

Anurag Saxena
Greenhorn

Joined: Oct 29, 2002
Posts: 13
Hi:
When I am trying to to this:
ResultSet rs = qs.executeQuery("SELECT * FROM webchiptran WHERE webchiptran.serialNo=\'85160814\'");
it works fine and return 2 rows.
Now if I receive 85160814 as a string say s and now how can I pass s.
I tried to convert s into and int but nothing works.
please help.
thanks.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Anurag Saxena:
Hi:
When I am trying to to this:
ResultSet rs = qs.executeQuery("SELECT * FROM webchiptran WHERE webchiptran.serialNo=\'85160814\'");
it works fine and return 2 rows.
Now if I receive 85160814 as a string say s and now how can I pass s.
I tried to convert s into and int but nothing works.
please help.
thanks.

ResultSet rs = qs.executeQuery("SELECT * FROM webchiptran WHERE webchiptran.serialNo='" + s + "'");


GenRocket - Experts at Building Test Data
Chandresh Patel
Greenhorn

Joined: Jul 05, 2002
Posts: 14
You can use PreparedStatement. It would be like this.
SELECT * FROM webchiptran WHERE webchiptran.serialNo=?);
and then use setString method on PreparedStatement to set your String value and execute.


Chandresh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Simple SQL question