aspose file tools*
The moose likes JDBC and the fly likes SELECT SCOPE_IDENTITY() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SELECT SCOPE_IDENTITY()" Watch "SELECT SCOPE_IDENTITY()" New topic
Author

SELECT SCOPE_IDENTITY()

Paul O'Neill
Ranch Hand

Joined: Mar 13, 2007
Posts: 40
I'm getting an exception The statement did not return a result set when I use this command as part of a SQL statement with SQL2005 and jdk1.5.0_10.

My PreparedStatement is inserting data into a table with executeQuery().

This always worked with SQL2000 and jdk1.4.2_13. I'm guessing the new MS SQL2005 jdbc driver has a problem??? If I run the same code directly in SQL, there's no issue.

Has anybody got any information on this?
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

please use executeUpdate() instead of executeQuery in your insert statement.

please share your code snippet here, sometime its help to find out the error.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31062
    
232

Originally posted by Paul O'Neill:
This always worked with SQL2000 and jdk1.4.2_13. I'm guessing the new MS SQL2005 jdbc driver has a problem??? If I run the same code directly in SQL, there's no issue.

Has anybody got any information on this?

That means that your original driver was allowing invalid commands through. executeQuery() should not be used for an insert/update. If it worked you were lucky. However the problem is still in your code and not the configuration.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Paul O'Neill
Ranch Hand

Joined: Mar 13, 2007
Posts: 40
I was just using execute() but it didn't like executeUpdate() either.

The statement is : INSERT INTO InterfaceData
(NextProcessingDate, ReceivedDate, SourceSystemName, Status, InterfaceType, ExternalID, InternalID,
Data, Direction, TransformedData, Message ) VALUES(?,?,?,?,?,?,?,?,?,?,?); select SCOPE_IDENTITY()


I have valid values in all the positions before running it.

Thanks!


Originally posted by Muhammad Saifuddin:
please use executeUpdate() instead of executeQuery in your insert statement.

please share your code snippet here, sometime its help to find out the error.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31062
    
232

Paul,
It looks like you have two statements. An update and a subsequent select. Have you tried running them separately?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SELECT SCOPE_IDENTITY()