This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling errors when running SQL query

 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • 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 ]
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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 ]
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic