Skip to Content.
Sympa Menu

freetds - JDBC: Protocol confusion retrieving result of "SELECT @@IDENTITY"

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Maraya Michael <maraya-michael AT dol.gov>
  • To: TDS Development Group <freetds AT franklin.oit.unc.edu>
  • Subject: JDBC: Protocol confusion retrieving result of "SELECT @@IDENTITY"
  • Date: Fri, 21 Apr 2000 12:12:39 -0400



I have an interesting problem here. But first, here's what I'm
using:

JDK 1.3.0RC1 for Win32
FreeTDS JDBC Driver snapshot as of 03/31/2000 (with a patch so it
will work with JDK 1.3)
MS SQL Server 6.5

Here's the table I defined:

CREATE TABLE application (
application_id int IDENTITY,
name varchar(8) NOT NULL,
version varchar(8) NOT NULL,
build_number int NOT NULL,
build_date datetime NOT NULL,
database_name varchar(32) NOT NULL,
user_table varchar(32) NOT NULL,
user_column varchar(32) NOT NULL,
record_information_id int NOT NULL
)
go

And here's the method that's producing an error:

/**
Returns the result of executing a "SELECT @@IDENTITY" against the
database.
Call this method immediately after adding a new record to retrieve
the
surrogate key assigned by the database.
@roseuid 38F22F000104
*/
public int getIdentity() throws SQLException {

// variable for return value
int retval = 0;

// create select statement
Statement stmt = getConnection().createStatement();

// build query
String query = "SELECT @@IDENTITY";

// execute query
ResultSet rs = stmt.executeQuery(query);

// retrieve value from ResultSet and store in retval
while (rs.next()) {
retval = rs.getInt(1);
}

// close statement
stmt.close();

// return the result
return retval;
}

Now, here's the error that I receive:

com.internetcds.jdbc.tds.TdsConfused: Protocol confusion- Was
expecting a length of 17, got 2
at com.internetcds.jdbc.tds.Tds.getDecimalValue(Tds.java:1621)
at com.internetcds.jdbc.tds.Tds.getRow(Tds.java:1921)
at com.internetcds.jdbc.tds.Tds.processSubPacket(Tds.java:1343)
at
com.internetcds.jdbc.tds.ResultSet_base.next(ResultSet_base.java:1508)
at control.DBConnection.getIdentity(DBConnection.java:95)
at entity.Application.insert(Application.java:115)
at control.AppHandler.saveChange(AppHandler.java:260)

I've tried the same method using the JDBC-ODBC bridge and it seems
to work okay. Can anyone confirm this problem or offer a solution? Should
I just format my query so that the result is padded with leading zeroes?
Thanks in advance for any and all assistance.





  • JDBC: Protocol confusion retrieving result of "SELECT @@IDENTITY", Maraya Michael, 04/21/2000

Archive powered by MHonArc 2.6.24.

Top of Page