This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Record insert sequence

 
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
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • 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 ]
 
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
 
rubbery bacon. crispy tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic