Callablestatement.execute() and clearParameter() causing exception



With SQL 2005 jdbc driver i connect to 2005 database using parameter
selectMethod=cursor.

//The procedure generates an id(long) and returns it.It also inserts
id and name into a table
cstmt = conn.prepareCall("{call test.testprocedure(?,?)}");
cstmt.registerOutParameter(1, Types.INTEGER);
cstmt.setLong(1,0);
cstmt.setString(2, "testname");
System.out.println(cst.toString());
cstmt.execute();
id=cstmt.getLong(1);
Throws the error,
com.microsoft.sqlserver.jdbc.SQLServerException: A server cursor cannot be
opene
d on the given statement or statements. Use a default result set or client
curso
r.
at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError
(Unknown Source)
at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown
Source)
at
com.microsoft.sqlserver.jdbc.SQLServerStatement.sendExecute(Unknown S
ource)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecute(Unknown
Sou
rce)
at
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(Unkno
wn Source)
at t.test(t.java:54)
at t.main(t.java:105)

The same code when run against a MSSQL 2000 database, gives this error:
com.microsoft.sqlserver.jdbc.SQLServerException: A server cursor is not
allowed
on a remote stored procedure or stored procedure with more than one SELECT
statement. Use a default result set or client cursor.
at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError
(Unknown Source)
at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown
Source)
at
com.microsoft.sqlserver.jdbc.SQLServerStatement.sendExecute(Unknown S
ource)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecute(Unknown
Sou
rce)
at
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(Unkno
wn Source)
at t.test(t.java:50)
at t.main(t.java:64)

When i connect using selectMethod=direct(the default), the execution goes
through. Also
when i do it as cstmt.executeUpdate(), it goes through.

Another bug i face is when cstmt.clearParameters() is given after
conn.prepareCall, i get
a null pointer exception in cstmt.getLong(1);
The same code used to work fine with MSSQL 2000 jdbc drivers without
any of these changes.


.



Relevant Pages

  • Re: Limit on LONGVARBINARY in MS JDBC driver?
    ... Could you post the code you have for the stored procedure ... > I have verified that the data is intact upon leaving the database by using ... > image data type to a LONGVARBINARY type prior to being queried by the ... I am using JDK v. 1.5.0_04 and MS JDBC Driver service pack 3. ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: Error when binding value to prepared statement with SQL Server 2005
    ... Database version is 9.0.1399 ... > Arto Basmadjian wrote: ... >> I'm using the latest jdbc driver to connect to an Sql Express ...
    (microsoft.public.sqlserver.jdbcdriver)
  • applet + database
    ... I'm planning to write a simple applet to display database records. ... Am I correct in guessing I need to dl the J2SE 1.4.2 package? ... It seems that I need a JDBC driver for whichever database I ... The JDBC code is copied to the client ...
    (comp.lang.java.programmer)
  • Re: What is the best way to interact with a JDBC database
    ... Instead of the MySQL JDBC driver use the MonetDB JDBC driver. ... I haven't tried Jruby except reading about it. ... to avoid using JRuby just for this requirement of accessing a JDBC database. ... this database from Ruby. ...
    (comp.lang.ruby)
  • Re: PreparedStatement
    ... It actually depends upon what JDBC driver ... But the "generic database access" class I am using to insert data to the ... to insert Strings into numeric fields (as long as the Strings are numbers, ...
    (comp.lang.java.help)