This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

try with resource issue  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am using try with resources in java to call a procedure and commit the results.
   
   The results are not getting commited in database.
   

   
   The following set of code should call the stored procedure and commit the results.
   
   The stored procedure calling is having no issue, only te resuts are not getting comitted



 
Bartender
Posts: 1088
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, welcome to the ranch !
If the stored procedure runs without error as you stated, please check if autocommit is turned on for the connection you use to call the SP.
What is "sessionImpl" ? Looks like you're getting your connection via Hibernate session. Is that true ?
 
anwesh matty
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I  am
getting connection via hibernate session. Will the auto commit help?
 
Claude Moore
Bartender
Posts: 1088
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using Hibernate, I think it's better to use Session object to commit your transaction, instead of setting autocommit manually.
 
anwesh matty
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Claude

Appreciate if you can send me an example to show how to commit a tranasaction for the callable
 
Sheriff
Posts: 5662
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, anwesh matty!

When posting code, be sure to UseCodeTags (that's a link) and learn HowToFormatCode (that's also a link).  I've added them for you this time.
 
Knute Snortum
Sheriff
Posts: 5662
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

anwesh matty wrote:Appreciate if you can send me an example to show how to commit a tranasaction for the callable  


If by "send me" you mean to send a private email, don't do that.  Post your answer to the forum so that everyone can benefit.

You commit transactions using your connection object:
The execute() method will return true if there is a resultSet or false if there is a number of updated rows or no result.  I set the variable isResultSet for clarity.  
 
Claude Moore
Bartender
Posts: 1088
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:
If by "send me" you mean to send a private email, don't do that.  Post your answer to the forum so that everyone can benefit.



Don't worry, I understand and fully agree to Coderanch's spirit: post questions and answers that could help every ranch member.
If I had a ready-to-post solution, I'd have been happy to help the OP, but unluckily I haven't any.

Knute Snortum wrote:
You commit transactions using your connection object:
The execute() method will return true if there is a resultSet or false if there is a number of updated rows or no result.  I set the variable isResultSet for clarity.  



What about this approach ? I would prefer to use explicitely transactions instead of issuing commit() / rollback() directly on connection.. but that's my humble opinion.


 
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, this is the more acceptable way to code that:


I have not used raw Hibernate in so long I no longer remember the Hibernate session semantics. I use Hibernate JPA these days. But a statement doesn't need to be declared in a try-with-resources I don't think. Either it opens and no exception or it doesn't open at all.

At the very least, using try-with-resources for the Transaction eliminates possible transaction state leakage.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!