• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Handling errors when running SQL query

 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you understand the definition of "transaction" ?
[ December 02, 2008: Message edited by: James Clark ]
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic