aspose file tools*
The moose likes JDBC and the fly likes Connection and Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connection and Statement" Watch "Connection and Statement" New topic
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: 24187
    
  34

Moving to our JDBC forum.


[Jess in Action][AskingGoodQuestions]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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>
 
 
subject: Connection and Statement