aspose file tools*
The moose likes JDBC and the fly likes Record insert sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Record insert sequence" Watch "Record insert sequence" New topic
Author

Record insert sequence

Vijay Rajaram
Greenhorn

Joined: Nov 17, 2003
Posts: 12
Hi,
I�m using a DB2 database. I�ve set the auto commit to false for my JDBC connection. In a for loop I�m preparing a insert statement and inserting the record. When I�m out of the for loop I�m committing the entire transaction.
The problem is:
I�m inserting the record in the order, say 1, 2, 3, 4 in the for loop. But when I actually look into the table its in the reverse order i.e 4, 3, 2, 1.
Is this the default behaviour of JDBC with auto commit set to false? Is there�s any way to change it? Or does it depend on the JDBC driver??
Thanks,
- VJ
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Hi VJ,

Is this the default behaviour of JDBC with auto commit set to false?

No, this is the default behaviour of any relational database.

Is there any way to change it?

No.

does it depend on the JDBC driver?

No.
As far as I know, for any [O]RDBMS, insert order does not guarantee retrieval order. If you want to retrieve records from your database in a particular order, then use an ORDER BY clause in your SELECT statement.
Good Luck,
Avi.
[ November 19, 2003: Message edited by: Avi Abrami ]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Is this the default behaviour of JDBC with auto commit set to false? Is there�s any way to change it?
the default behaviour is specific to the driver. I've worked with some where autocommit defaults to true, and some where it is false. It is always a good idea to set it no matter what the default is for the driver so there isn't any room for assumption errors.
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Record insert sequence
 
Similar Threads
commit problem - always happens even if set to false!!
JTA
How to insert all the records except the failed one.
Inserting junk values while using Prepared Statement
A servlet code written to add details in database but not happening?