Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PreparedStatement ???

 
Sanjeev Shahi
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we use more than one SQL im prepraredStatement? If yes please give example
thanks,
ss
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sanjeev Shahi
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic