This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 15286
    
    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 - A Test Data Generation Platform
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
 
Don't get me started about those stupid light bulbs.
 
subject: Simple SQL question
 
Similar Threads
Doubt on deploying servlet
forward and filter
Beginner Struts Problem (Solved)
JButton Syntax Question
Cannot retrieve mapping for action