Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes PreparedStatement ??? 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 ???" Watch "PreparedStatement ???" New topic
Author

PreparedStatement ???

Sanjeev Shahi
Ranch Hand

Joined: Feb 26, 2001
Posts: 83
Can we use more than one SQL im prepraredStatement? If yes please give example
thanks,
ss
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Sanjeev
I'm not sure I understand your question. Can you use more than one preparedStatement in your code?
Sure, just make sure you give each one a different variable name or you'll just keep rewrtining over the previous one.

Or are you asking if you can have more than one SQL statment associated with a preparedStatement?
The answer to that is yes, but it might defeat the purpose of the preparedStatement. IF you create a single preparedStatement in your class and keep switching the code in it then you loose the benefit of having a prepared statement. If, for example, you have an insert statement in your preparedStatement and you use it then create a new preparedStatement with the same variable name you've just lost the first one.
If your statements are for one use only then you might not need the preparedStatemnet at all - unless you set them all up when your class is first loaded and they just sit there and wait on the user, that would save a little overhead and time but probably not too much unless they are fairly lengthy queries.
hope that helps
Dave


Dave
Sanjeev Shahi
Ranch Hand

Joined: Feb 26, 2001
Posts: 83
Hi! dave ,
Thanks for replying.
code:
--------------------------------------------------------------------------------
preparedStatement ps1 = conn.prepareStatement("sql goes here");preparedStatement ps2 = conn.prepareStatement("sql goes here");preparedStatement ps3 = conn.prepareStatement("sql goes here");
Actually I meant can we put more than one SQL statement in the bracket.
eg:
PreparedStatment ps1 = con.prepareStatment(
select * from table1,
select* from table2);
I hope I am clear.
ss
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

you can only do this through the CallableStatement interface. You create the database stored procedure which can execute many sql statements and call it from the java program.
Jamie
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: PreparedStatement ???