Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / December 2003

Tip: Looking for answers? Try searching our database.

Stored Procedure Not Committing

Thread view: 
Kathy - 05 Dec 2003 15:03 GMT
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
Joe Weinstein - 05 Dec 2003 16:01 GMT
> 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
[quoted text clipped - 10 lines]
> 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:
>
[quoted text clipped - 31 lines]
> Thanks!
> Kathy
Tim Jowers - 16 Dec 2003 19:15 GMT
> > 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
[quoted text clipped - 50 lines]
> > 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.