Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple prepareStatement on one Connection

 
Sidd Nakade
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Sidd Sidd ",
Please check your private messages.
 
Raees Uzhunnan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • 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.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4028
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raees Uzhunnan,
Please check your private messages.
 
Raees Uzhunnan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize ben ; Yeah you are right ! if you are asking questions, be man enough !!
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • 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
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Sidd N",
Please check your private messages, again.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4028
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic