AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Stored Procedure Not Committing

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Kathy
Guest





PostPosted: Fri Dec 05, 2003 3:03 pm    Post subject: Stored Procedure Not Committing Reply with quote



I am using a Callable Statement to run a stored procedure in the database.
The stored procedure takes an input parameter and passes an output parameter
of type int. The output parameter is used to perform a test to see if the
stored procedure worked properly, or passed some logic tests on the database
side. If the output parameter is 0, then I commit, otherwise I must perform
a rollback.

Now, the problem is, everything looks like it's running perfectly. I get no
SQL exceptions, my output parameter is 0, so I call Connection.commit() and
Connection.setAutoCommit(true). However, the database doesn't update, it's
as if the commit statement never gets run, but no exception is thrown.
Note: If I run this in autocommit mode it runs fine, but I am not able to
perform an explicit rollback when I get an incorrect output parameter, so my
data will change when it should NOT change.

Here is the code:

con.setAutoCommit(false);
CallableStatement cs = con.prepareCall("{call mysp (?,
?)}");
cs.registerOutParameter(2, java.sql.Types.INTEGER);
cs.setInt(1, 12);
cs.execute();
int myresult=cs.getInt(2);
System.out.println("Update done for: 12");
System.out.println("Result=" + myresult);
if (myresult!=0) {
System.out.println("Update failed!");
try {con.rollback();
con.setAutoCommit(true);
} catch (SQLException xcp)
{System.out.println("Exception: " + xcp.getMessage();}
} else {con.commit();
con.setAutoCommit(true);
}


Output when I test:
Update done for: 12
Result=0

The entire thing is surrounded with a SQLException handler etc, but this is
the core of the code which performs the function.

The only odd thing about the stored procedure, is that it uses a temp table
to do some data manipulation before it updates the data that I am affecting.

Any suggestions would be appreciated.

Thanks!
Kathy


Back to top
Joe Weinstein
Guest





PostPosted: Fri Dec 05, 2003 4:01 pm    Post subject: Re: Stored Procedure Not Committing Reply with quote





Kathy wrote:

Quote:
I am using a Callable Statement to run a stored procedure in the database.
The stored procedure takes an input parameter and passes an output parameter
of type int. The output parameter is used to perform a test to see if the
stored procedure worked properly, or passed some logic tests on the database
side. If the output parameter is 0, then I commit, otherwise I must perform
a rollback.

Now, the problem is, everything looks like it's running perfectly. I get no
SQL exceptions, my output parameter is 0, so I call Connection.commit() and
Connection.setAutoCommit(true). However, the database doesn't update, it's
as if the commit statement never gets run, but no exception is thrown.
Note: If I run this in autocommit mode it runs fine, but I am not able to
perform an explicit rollback when I get an incorrect output parameter, so my
data will change when it should NOT change.

Hi. Interesting! What DBMS are you using, and what jdbc driver?
Off hand, this seems all OK. Can you show us the text of the procedure?
Joe Weinstein at BEA

Quote:

Here is the code:

con.setAutoCommit(false);
CallableStatement cs = con.prepareCall("{call mysp (?,
?)}");
cs.registerOutParameter(2, java.sql.Types.INTEGER);
cs.setInt(1, 12);
cs.execute();
int myresult=cs.getInt(2);
System.out.println("Update done for: 12");
System.out.println("Result=" + myresult);
if (myresult!=0) {
System.out.println("Update failed!");
try {con.rollback();
con.setAutoCommit(true);
} catch (SQLException xcp)
{System.out.println("Exception: " + xcp.getMessage();}
} else {con.commit();
con.setAutoCommit(true);
}


Output when I test:
Update done for: 12
Result=0

The entire thing is surrounded with a SQLException handler etc, but this is
the core of the code which performs the function.

The only odd thing about the stored procedure, is that it uses a temp table
to do some data manipulation before it updates the data that I am affecting.

Any suggestions would be appreciated.

Thanks!
Kathy




Back to top
Tim Jowers
Guest





PostPosted: Tue Dec 16, 2003 7:15 pm    Post subject: Re: Stored Procedure Not Committing Reply with quote



Joe Weinstein <joeNOSPAM (AT) bea (DOT) com> wrote

Quote:
Kathy wrote:

I am using a Callable Statement to run a stored procedure in the database.
The stored procedure takes an input parameter and passes an output parameter
of type int. The output parameter is used to perform a test to see if the
stored procedure worked properly, or passed some logic tests on the database
side. If the output parameter is 0, then I commit, otherwise I must perform
a rollback.

Now, the problem is, everything looks like it's running perfectly. I get no
SQL exceptions, my output parameter is 0, so I call Connection.commit() and
Connection.setAutoCommit(true). However, the database doesn't update, it's
as if the commit statement never gets run, but no exception is thrown.
Note: If I run this in autocommit mode it runs fine, but I am not able to
perform an explicit rollback when I get an incorrect output parameter, so my
data will change when it should NOT change.

Hi. Interesting! What DBMS are you using, and what jdbc driver?
Off hand, this seems all OK. Can you show us the text of the procedure?
Joe Weinstein at BEA


Here is the code:

con.setAutoCommit(false);
CallableStatement cs = con.prepareCall("{call mysp (?,
?)}");
cs.registerOutParameter(2, java.sql.Types.INTEGER);
cs.setInt(1, 12);
cs.execute();
int myresult=cs.getInt(2);
System.out.println("Update done for: 12");
System.out.println("Result=" + myresult);
if (myresult!=0) {
System.out.println("Update failed!");
try {con.rollback();
con.setAutoCommit(true);
} catch (SQLException xcp)
{System.out.println("Exception: " + xcp.getMessage();}
} else {con.commit();
con.setAutoCommit(true);
}


Output when I test:
Update done for: 12
Result=0

The entire thing is surrounded with a SQLException handler etc, but this is
the core of the code which performs the function.

The only odd thing about the stored procedure, is that it uses a temp table
to do some data manipulation before it updates the data that I am affecting.

Any suggestions would be appreciated.

Thanks!
Kathy



Kathy,

I ran into this too... SQL Server (and one would infer Sybase) does
not always throw SQLException or even set SQLWarnings. To no avail I
even tried the TSQL "RaisError" in the stored proc. Well, it seems
that way until you call getMoreResults()... something about the
exception being in the stream from the db... that's a bugger with
using CallableStatement but after adding the getMoreResults after
Execute then life is good once again. (Until the next time :-0)

TimJowers

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.