Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Record insert sequence

 
Vijay Rajaram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic