my dog learned polymorphism*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 24183
    
  34

Moving to our JDBC forum.


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

Joined: Jan 10, 2002
Posts: 60774
    
  65

"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>
 
Don't get me started about those stupid light bulbs.
 
subject: Connection and Statement
 
Similar Threads
Need a sample query
need help in connection performance...
Problem updating batch records in Oracle through Java - URGENT
problem in formatting date
Problem with ejb transaction