wood burning stoves 2.0*
The moose likes JDBC and the fly likes PreparedStatement with dynamic variable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "PreparedStatement with dynamic variable?" Watch "PreparedStatement with dynamic variable?" New topic
Author

PreparedStatement with dynamic variable?

Joseph Smithern
Ranch Hand

Joined: Feb 11, 2006
Posts: 89
Is it possible to use a PreparedStatement with my below
SQL because I am inserting a dynamic variable.



Please advise how it can look if I use a PreparedStatement because I dont see how this would work if I need to insert the myData dynamic variable?

Insert into firstTable (city, tableid) values (?,?)
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Joseph,
Why can't you use:
stmt.setString(mybean.getCity());
stmt.setInt(myData);

They are both dynamic fields. What makes myData different?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Joseph Smithern
Ranch Hand

Joined: Feb 11, 2006
Posts: 89
Originally posted by Jeanne Boyarsky:
Joseph,
Why can't you use:
stmt.setString(mybean.getCity());
stmt.setInt(myData);

They are both dynamic fields. What makes myData different?



Thanks for your quick reponse!

I didnt know I could do it that way and I will use what you suggested tomorrow morning.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PreparedStatement with dynamic variable?
 
Similar Threads
how to insert foreign key into JSP through servlet
image and form data upload problem
Help: Inserting non-english(Hebrew) characters in MS SQL SERVER 2005
Database helper class and closing question
Tags/Tag Libs help