Tuesday, 15 January 2013

sql server - SQLServerException: The statement did not return a result set when executing SQL -


I am using sqljdbc4.jar (sqljdbc_2.0) version.

To get an identity like this, select one of the + one execution:

  In the beginning, the date date option (description, code) value ('dateRange. QuickPick.option.all ',' ALL '); Select SCOPE_IDENTITY () END  

and I'm getting:

 com.microsoft.sqlserver.jdbc.SQLServerException: This statement did not return the results set. 

The line is:

  st.executeQuery (updateQuery)  

Any ideas?

was updated from SQL 2000 to SQL 2005 and switched to Microsoft SQL Server 2005 JDBC Driver version 1.2 . I got the error "No results were found from selection", when an integration was performed by SELECT SCOPE_IDENTITY (). "I resolved this problem by using execGetReport () and getGeneratedKeys instead of executing it. Here is the code before and after.

Note: The connection used in this example is java .sql.connection is not com.microsoft.sqlserver.jdbc.sqlServerConnection.

SQL 2000 code

  string dbURL = "Jdbc: sqlserver" + ":" "+ dbServer +": "+ dbServerPort +"; SelectedMethod = cursor; database name = "+ dbName +"; User = xxx; password = xxx "; category. Fornum ("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Java.sql.Connection connection = DriverManager.getConnection (dbURL); Sql = "Enter value in contact (name) ('ABC'); select SCOPE_IDENTITY ()"; Place created ps = connection.prepareStatement (sql); Resultset = ps.executeQuery (); If (rsnext ()) {long id = rs.getLong (1); System.out.println ("id =" + id);}  

SQL 2005 code

  string dbURL = " Jdbc: sqlserver "+": // "+ dbServer +": "+ dbServerPort +"; SelectedMethod = cursor; database name = "+ dbName +"; user = xxx; password = xxx "; Class .for name ("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Java.sql.Connection connection = DriverManager.getConnection (dbURL); Sql = "Enter the contact (name) value ('ABC'); select SCOPE_IDENTITY ()"; PreparedStatement ps = connection.prepareStatement (sql); Ps.executeUpdate (); Do not use // execute () Otherwise you can get the error // statement // should be executed before any result can be obtained on the next // getGeneratedKeys statement. ResultSet rs = ps.getGeneratedKeys (); If (rsnext ()) {long id = rs.getLong (1); System.out.println ("id =" + id);}  

No comments:

Post a Comment