File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
162

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?