This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes PreparedStatement always returns {-2, -2, -2,...} Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: PreparedStatement always returns {-2, -2, -2,...}
 
Similar Threads
What Would Cause A Method That Inserts Records To Throw An Exception?
Any Possibilities to get other than SQLException while using executeUpdate() method
My sql query returns zero rows
Exception in Batch Update
Batch updates of preparedstatement