jQuery in Action, 2nd edition*
The moose likes JDBC and the fly likes Savepoint in jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Savepoint in jdbc
 
Similar Threads
Dynamically creating stored Procudure in JAVA
Set Method for Oracle Database
procedure call
What Would Cause A Method That Inserts Records To Throw An Exception?
retrieve data in PL/SQL proc using JDBC in Websphere