• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple SQL question

 
Anurag Saxena
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 + "'");
 
Chandresh Patel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic