• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

java.sql.Connection - does not throw SQLException on calling commit() or rollback() - in AutoCommit

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This query is related to JDBC Transaction.(java.sql.Connection)

I am using DB2 for z/OS.

As per the documentation, commit() or rollback() on Connection instance should throw SQLException if the Connection is under auto-commit mode. I have tried to test this, I do not get the exception.
Is it vendor- dependent ?



I get the below output.

true
rows updated: 3
 
Greenhorn
Posts: 22
Oracle Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the javadoc states the conditions under which the method will be called in addition the reason which is responsible for throwing SQLException
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am learning java thanks sharing this post
 
Vinay Kumar T M
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OCP test do have this question in scope. It says, SQLException will be thrown if we try to commit or rollback when the connection is in auto-commit mode. I could not re create this scenario.

even some of the sample questions says, SQLException will be thrown.

To my understanding, it should throw SQLException. is it wrong ?
 
Sibendu Dey
Greenhorn
Posts: 22
Oracle Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will be thrown when an database access error happens. Try performing a database operation which is not valid like inserting some data into a non-existent column. I guess you should get a SQLException.
 
Vinay Kumar T M
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Try performing a database operation which is not valid like inserting some data into a non-existent column. I guess you should get a SQLException.



Thats the purpose of SQLException right ?. ofcourse, it should throw if we try to do invalid things. My question is not about doing invalid things. It is about the behaviour which is contradicting the oracle documentation. I might be very much , wrong...

So please help me understand.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic