File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes PreparedStatement always returns {-2, -2, -2,...} Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "PreparedStatement always returns {-2, -2, -2,...}" Watch "PreparedStatement always returns {-2, -2, -2,...}" New topic
Author

PreparedStatement always returns {-2, -2, -2,...}

Heath Lilley
Ranch Hand

Joined: Jan 09, 2001
Posts: 72
Here we go...
Java Env:WSAD 5.0
Local OS:Windows 2000 Pro
DB:Oracle 9i (9.2.0.1)
DB OS:Solaris 8.0(I think)

I am using a PreparedStatement.addBatch(), to do multiple database updates. In my first attempt I tried to use Replacable Parameters to set my values into the statement.
This worked with 1 or more records, however, the int array that PreparedStatement.executeBatch() return contains nothing but -2's. Now, I know that -2 means "Successful, but updated number of records is unknown". But it would be nice to make sure the number of updated are what I think they should be.
After seeing all of the -2's returned I modified my method to "build" the sql statements by using a StringBuffer. I then used Statement.addBatch(sqlString). This time the array returned all 1's which is what I wanted.
My question is, does anyone know why PreparedStatement.executeBatch() returns -2's and Statement.executeBatch returns 1's while running the same queries?
Here is a snippet of my code the large block of commented out code is from my second attempt. I am including it for posterity. At the bottom recordCount is an int[].

Thanks in advance.
[ May 22, 2003: Message edited by: Heath Lilley ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PreparedStatement always returns {-2, -2, -2,...}