File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes handling sql exception, error code ... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "handling sql exception, error code ..." Watch "handling sql exception, error code ..." New topic
Author

handling sql exception, error code ...

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3359

Hi all.
I have some questions about transactions.
1. as you know, getErrorCode( ) method returns a vendor's error code, so maybe differ from
database to other.
does getSQLState( ) method return a fixed value for a specific problem ?
I mean, I have MYSQL database and I shut it down, when catching the SQLException and calling
getSQLState( ) method, I got 08S01.
if I have oracle database and repeat these steps, will I recieve the same status ?
2. I have the following code :
try {
con.setAutoCommit(false);
// create some statements and execute them
con.commit( );
con.setAutoCommit(true);
} catch (SQLException e) {
// needs to handle
}
now, if SQLException is thrown , what should I do at catch statement ?
should I called con.rollback( ) method and then rethrow the exception ?
3. what does setHoldability( ) method mean ? when to use it ?
I have read the API but I don't understand it.
4. In which situation I should use save points ?
your help is really appreciated.
thanks a lot.
tommy k. lee
Greenhorn

Joined: Jun 16, 2004
Posts: 20
Are you using an EJB container to create your data access / persistence classes? (i.e. entity beans , session beans)

Or are you writing a stand-alone JDBC application?

For instance, if you are using an EJB container, the transactions are managed by the EJB container itself. The transactions are usually declared in the deployment descriptors at deploy time, rather than within your application code itself.

However, if you are writing a stand-alone JDBC application, you will need to manage the transactions manually, including roll-backs upon exceptions.

You can find more info @ http://www.javaworld.com/javaworld/jw-07-2000/jw-0714-transaction.html


SCJP,SCJD SCEA, SCWCD, SCBCD<br />OCP DBA 8i / 9i<br />CISSP, PMP, PHR<br />CCNA, CCDA <br /><a href="http://www.certgear.com" target="_blank" rel="nofollow">http://www.certgear.com</a>
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: handling sql exception, error code ...
 
Similar Threads
Design Decision: Database User List
when to use catch block and when to use throws
How to get exact exception type
rollback, save point .....
how to properly catch/display exception in jsp ?