?
Solved

executeUpdate returns -1?

Posted on 2006-07-05
16
Medium Priority
?
771 Views
Last Modified: 2008-02-01
All,

What can cause executeUpdate to return -1?

Paul
0
Comment
Question by:PaulCaswell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +3
16 Comments
 
LVL 14

Expert Comment

by:StillUnAware
ID: 17041012
What was the query?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17041015
Shouldn't be anything that can cause that
0
 
LVL 92

Assisted Solution

by:objects
objects earned 186 total points
ID: 17041050
technically it shouldn't, but depends on the driver.
what driver ru using?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 86

Accepted Solution

by:
CEHJ earned 189 total points
ID: 17041062
It would have to be a driver that is incorrect vis-a-vis the spec
0
 
LVL 8

Expert Comment

by:colr__
ID: 17041093
Can you post the code?
0
 
LVL 8

Expert Comment

by:colr__
ID: 17041103
Can you not just ignore it anyway? Since you shouldnt be expecting to recieve a value back from an update, if it does return a value, can you not just ignore it?

The only problem with this is that -1 would typiclally imply the update failed (although as CEHJ says, this is incorrect as to the Java spec).
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 17041145
Instead of returning -1, you should expect an SQLException.
This value obviously indicate an error (maybe not well managed by the driver) :
  - invalid sql query
  - connection error
  - other (disk is full, ...)

If you want an exception, then :
   if (ps.executeUpdate()<0) throw new SQLException("unknown error");
0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 17041252
All,

Cracked it!

Thanks for all the quick help!

The problem was twofold:

1) I was using:

          makeTable.executeUpdate(query);
          collected = makeTable.getUpdateCount();

This works fine against a SQL2005 database but fails on SQL2000 (the getUpdateCount returns -1). I didnt realise that executeUpdate returned the count. :-(

This works:

          collected = makeTable.executeUpdate(query);

2) I make a temp table '#tempTable' using an INSERT INTO, then run a query against it. This works fine when driving SQL2005 Express. This went tilt against a SQL2000 database. A little research and experimentation shows that temp tables are handled slightly differently between the two versions. Using #tableName works fine in 2005 but you have to use ##tableName when running against 2000.

Note that the Java drivers are also different between the two versions so the difference may be in the driver rather than the database.

Again, thanks all for the suggestions.

I need to think about points distribution. No time now. Back later. If you have any preferences, let me know.

Paul
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 17041309
As you found the solution, you can ask refunding the points.
0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 17041389
>> As you found the solution, you can ask refunding the points.
Is anything here of value to PAQ? I am no Java guru. Is this just noise or valuable? I wont be offended :-)

Paul
0
 
LVL 8

Expert Comment

by:colr__
ID: 17041420
i think it should be PAQd, the soltuion is here...
0
 
LVL 92

Expert Comment

by:objects
ID: 17041464
> Note that the Java drivers are also different between the two versions so the difference may be in the driver rather than the database.

I actually mentioned that it was dependant on the driver ;)
0
 
LVL 92

Expert Comment

by:objects
ID: 17041468
do as you feel fit though, doesn't bother me :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17041743
The problem was nothing to do with the driver. It was due to collecting the result of getUpdateCount instead of executeUpdate
0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 17043112
>> The problem was nothing to do with the driver. It was due to collecting the result of getUpdateCount instead of executeUpdate

We have no way of knowing if it was the driver or SQL. getUpdateCount works with the SQL2005 and its driver while it returns -1 with SQL2000 and its driver. Both right! Split points! Sorry for the B.

Paul
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17043206
>>getUpdateCount works with the SQL2005 and its driver while it returns -1 with SQL2000 and its driver.

Yes, but the question was about why *executeUpdate* returns -1

>>What can cause executeUpdate to return -1?

and the following code:

>>
makeTable.executeUpdate(query);
collected = makeTable.getUpdateCount();
>>

clearly shows, as i mentioned in my last comment, the result being collected from getUpdateCount (which *can* return -1) and *not* executeUpdate
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question