wood burning stoves 2.0*
The moose likes JDBC and the fly likes Handling errors when running SQL query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Handling errors when running SQL query" Watch "Handling errors when running SQL query" New topic
Author

Handling errors when running SQL query

shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Hi Guys

I have the following method in my sql bean:

I am alittle inexperienced when it comes to handling errors. I am using a try/catch which will log errors, I also have a return statement which will be used to inform the user if anything goes wrong. Do I need anything else ? I was told I should have a commit/rollback in there, but how to do implement it?




.
[ December 02, 2008: Message edited by: shaf maff ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Transaction demarcation is a big topic. Handling and programming transactions can be done in many different ways. Basically, you want to identify what is a "transaction" in terms of your application. You would first need to get a good understanding of the definition of a "transaction."

Once you have identified the transaction, you then need to look at the operations of the transaction and which methods implement those operations.

Next, you need to look at how you have designed the business logic and the database logic and look at the business methods and the persistence methods.

Check out the Java Transaction API for more info. Below is an example for study:


[ December 02, 2008: Message edited by: James Clark ]
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Thanks for the reply. I had a quick read of the api. How is this different from the way I have coded my one above ? It looks like this should only be used in transactions, I am not doing any so should I just stick to my code ?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Do you understand the definition of "transaction" ?
[ December 02, 2008: Message edited by: James Clark ]
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Well, its usually a transaction between parties. Its usually attributed to money, unless java means it in its more general way? :s
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
I suggest that you execute a Yahoo search on the term "database transaction demarcation." IBM and the Hibernate group have good material that covers transaction management and programming.

Enjoy!
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
I read up on the java website and it makes sense now. I have a question, in the code you posted, I wanted to know for the following line of code:

the exUpdate is my custom function which runs the sql statement right ?


.
[ December 02, 2008: Message edited by: shaf maff ]
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Originally posted by shaf maff:
the exUpdate is my custom function which runs the sql statement right ?



yes that's what DAO class methods are meant for. They provide an interface to execute queries.


SCJP, SCWCD.
|Asking Good Questions|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Handling errors when running SQL query