Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java/JDBC/MS SQL server - error processing numeric datatypes

Status
Not open for further replies.

jshepher

Programmer
Mar 15, 2002
1
US
I have a simple script that runs on Unix and accesses MS SQL Server. The problem I'm having is that I cannot read numeric defined datatypes. I received the following error:

com.internetcds.jdbc.tds.TdsConfused: Protocol confusion- Was expecting a lengt5
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.fillInStackTrace(Compiled Code)
at java.lang.Throwable.<init>(Compiled Code)
at java.lang.Exception.<init>(Exception.java:42)
at com.internetcds.jdbc.tds.TdsException.<init>(TdsException.java:52)
at com.internetcds.jdbc.tds.TdsConfused.<init>(TdsConfused.java:46)
at com.internetcds.jdbc.tds.Tds.getDecimalValue(Compiled Code)
at com.internetcds.jdbc.tds.Tds.getRow(Compiled Code)
at com.internetcds.jdbc.tds.Tds.processSubPacket(Compiled Code)
at com.internetcds.jdbc.tds.ResultSet_base.next(Compiled Code)
at jdbc.main(Compiled Code)
Got an exception!
Protocol confusion- Was expecting a length of 17, got 5

Here are the column defs:

Name DataType Length Value
--------------------------------------------------------------------------------------
recid numeric 18,0 12345678901
account varchar 50 00100101




Heres the script:

java.sql.Connection conn = DriverManager.getConnection(url, usr, pswd);
java.sql.Statement stmt = conn.createStatement();

ResultSet rs;

rs = stmt.executeQuery(&quot;SELECT recid, account FROM some_table&quot;);

while ( rs.next() ) {
String rec_id = rs.getString(&quot;recid&quot;);
String acct = rs.getString(&quot;account&quot;);
System.out.println(&quot;Record Id: &quot; + rec_id);
System.out.println(&quot;Account: &quot; + acct.trim());
}
conn.close();

} catch (Exception e) {
System.err.println(&quot;Got an exception! &quot;);
System.err.println(e.getMessage());

}


I get this message even if I don't set rec_id variable and ignore recid.
If I remove recid from Select, script executes without error..........
 
looks like you are trying to read a numeric column with a getString method of the result set. Try using the getLong() method instead and putting it into a numeric data type such as an int, long or double - see if this has any effect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top