This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Simple SQL question  RSS feed

 
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.
 
Ranch Hand
Posts: 15304
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 + "'");
 
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.
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!