Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple prepareStatement on one Connection

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
how does multiple prepared statment work on one connection object.
Unknowingly I was using it for a while and it does work. Now while reviewing my code i was wondering how does this actually work.

Here is the code sample:
Connection box1Con = Commons.getBOX1DBConnection();
Connection box2Con = Commons.getBOX2DBConnection();
queryResource = readResource();

PrepareStatement ps1 = box1Con.prepareStatement(query1);
PrepareStatement ps1 = box2Con.prepareStatement(query2);

Thanks for the help in advance.
Sidd
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Sidd Sidd ",
Please check your private messages.
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no need to have two connection for 2 prepared statement!. You can open any number of prepared statements as long as you are closing it after closing the ResutSets

Whats up with Ben ? he is sending private messages !. post it man ; let others too read !

Raees
 
Marshal
Posts: 79028
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raees Uzhunnan:
Whats up with Ben ? he is sending private messages !. post it man ; let others too read !

Raees

The PM is private because it is private information.
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Campbell Ritchie:
The PM is private because it is private information.



The name "Sidd Sidd" might be a clue...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raees Uzhunnan,
Please check your private messages.
 
Raees Uzhunnan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I apologize ben ; Yeah you are right ! if you are asking questions, be man enough !!
 
Campbell Ritchie
Marshal
Posts: 79028
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Scott Selikoff:


. . . might be a clue...

I was trying to keep quiet about that.
 
Sidd Nakade
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to mention, I am using both the prepareStatements in a loop.
ex:
Connection box1Con = Commons.getBOX1DBConnection();
Connection box2Con = Commons.getBOX2DBConnection();
queryResource = readResource();

PrepareStatement ps1 = box1Con.prepareStatement(query1);
PrepareStatement ps1 = box2Con.prepareStatement(query2);

for(int i=0; i < 100; i++){
rs1 = ps1.executeQuery();
rs1.....
rs1.close();


rs2 = ps2.executeQuery();
rs2.....
rs2.close();

}


ps1.close();
ps2.close();


Thanks
Sidd N
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Sidd N",
Please check your private messages, again.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Campbell Ritchie:
I was trying to keep quiet about that.



Well I've got to keep 'the conspiracy' under wraps.
 
Sidd Nakade
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raees Uzhunnan, as you mentioned using multiple prepared statements is not an issue if we close it after closing resultset. But in my example I am closing the result set and not closing the preparedstatment. Do you see this as an issue.
 
Raees Uzhunnan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not an issue ; you can call as many execute as possible on a statement before closing it. But make sure you are not creating as many statements for the same query

Raees
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic