Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection and Statement

 
Johnson Tmmet
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our JDBC forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic