This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Savepoint in jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Savepoint in jdbc" Watch "Savepoint in jdbc" New topic
Author

Savepoint in jdbc

Ann Sebastian
Ranch Hand

Joined: Sep 21, 2005
Posts: 37
Hi all,
I want to use savepoints to execute my functions.Functions do not have an
explicit commit statement.


On executing the folowing code snippet I get Error:


c = DriverManager.getConnection(url, username, password);
System.out.println("connection successful");

c.setAutoCommit(false);
Savepoint starttrans=c.setSavepoint("CustomBusinessLogic");


//First Function
CallableStatement stmt = c.prepareCall("Begin ? := fnCreateVoucherTb(?,?,?,?,?,?,?,?); End;");
stmt.registerOutParameter(1,Types.INTEGER);
System.out.println("Executing Create Function");
stmt.setInt(2 , 1);
stmt.setString(3 , "Nu");
stmt.setString(4 , "BNumber");
stmt.setString(5 , "29-Sep-05");
stmt.setString(6 , "29-Oct-05");
stmt.setInt(7 , 3);
stmt.setInt(8 , 3);
stmt.setString(9 , "29-Sep-05");
stmt.executeUpdate();
pk = stmt.getInt(1);
System.out.println(pk);
stmt.close();

//Second Function
stmt = c.prepareCall("Begin ? := fnSaveVoucherTb(?,?,?,?,?,?,?,?,?,?); End;");
stmt.registerOutParameter(1,Types.INTEGER);
stmt.setInt(2,1);
stmt.setInt(3,127);
stmt.setString(4 , "FirstFunction");
stmt.setString(5 , "BatchNumber1");
stmt.setString(6 , "03-OCT-05");
stmt.setString(7 , "03-OCT-05");
stmt.setInt(8 , 3);
stmt.setInt(9 , 3);
stmt.setString(10 , "03-OCT-05");
stmt.setString(11 , "2005-10-05 10.58.38.6");
System.out.println("Save Function: set the parameters");
stmt.execute();
System.out.println("Procedure Executed");
pk=stmt.getInt(1);

c.rollback(starttrans);
}
catch(SQLException e)
{
System.out.println("Error Occured" + e);
}


ERROR::
Error Occuredjava.sql.SQLException: ORA-01086: savepoint 'CUSTOMBUSINESSLOGIC' never established


What is the problem
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32508
    
214

Ann,
Welcome to JavaRanch!

On which line of code does the code throw the exception? When you set the savepoint at the beginning or when you rollback to it?


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Savepoint in jdbc
 
jQuery in Action, 3rd edition