Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Savepoint in jdbc

 
Ann Sebastian
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 35976
422
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!