| Author |
Connection and Statement
|
Johnson Tmmet
Greenhorn
Joined: Oct 27, 2005
Posts: 8
|
|
Hi, I have a question. I have to insert 5 records in a database. I get the connection from datasource and create the preparedStatement. My question is, is it good to use one Connection and preparedStatement to insert all the 5 records or do I have to get the connection using ds.getConnection() and preparedStatement for each insert? Which one would be better in performance? Please note that I don't want to use executebatch() for this. Thanks in advance,
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
is it good to use one Connection and preparedStatement to insert all the 5 records
Yes.
Please note that I don't want to use executebatch() for this.
Why not?
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24039
|
|
|
Moving to our JDBC forum.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
"Johnson kkkk", There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it. In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. Thanks! bear Forum Bartender
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Tom Blough
Ranch Hand
Joined: Jul 31, 2003
Posts: 263
|
|
Originally posted by Jason: Please note that I don't want to use executebatch() for this. Originally posted by Paul Sturrock: Why not?
Biggest reason I can think of is that if one statement in a batch fails, all statements are rolled back. [ October 27, 2005: Message edited by: Tom Blough ]
|
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Connection and Statement
|
|
|