当前位置: 代码迷 >> Sybase >> Sybase报Invalid packet type 0x22异常
  详细解决方案

Sybase报Invalid packet type 0x22异常

热度:10094   发布时间:2013-02-26 00:00:00.0
Sybase报Invalid packet type 0x22错误

今天使用Sybase(15.7 Developer版)查询DB时,遇到了很诡异的错误,错误异常如下:

<-- java.sql.SQLException: TDS Protocol error: Invalid packet type 0x22	at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2284)	at net.sourceforge.jtds.jdbc.TdsCore.isDataInResultSet(TdsCore.java:792)	at net.sourceforge.jtds.jdbc.JtdsResultSet.<init>(JtdsResultSet.java:146)	at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:424)	at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:693)	at com.trs.infra.persistent.BaseObjs.loadCurrentData(BaseObjs.java:1321)	at com.trs.infra.persistent.BaseObjs.open(BaseObjs.java:1437)	at com.trs.ekp.stat.obtain.StatResultObtainMgr.queryStatResults(StatResultObtainMgr.java:194)	at com.trs.ekp.stat.domain.ExpertLevelMgrTest.testGetAllExpertLevels(ExpertLevelMgrTest.java:51)	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)	at java.lang.reflect.Method.invoke(Method.java:597)	at junit.framework.TestCase.runTest(TestCase.java:154)	at junit.framework.TestCase.runBare(TestCase.java:127)	at junit.framework.TestResult$1.protect(TestResult.java:106)	at junit.framework.TestResult.runProtected(TestResult.java:124)	at junit.framework.TestResult.run(TestResult.java:109)	at junit.framework.TestCase.run(TestCase.java:118)	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)Caused by: net.sourceforge.jtds.jdbc.ProtocolException: Invalid packet type 0x22	at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2271)	... 24 more

 

经过定位,最终发现是指定的表中的字段个数太多(我这个表中有575个字段),把sql语句修改成select 字段1,字段2 …… from 表

问题不再重现。

select * 时,底层虽然也会提取所有字段,但是会报这个错误,如果我们把所有字段列在select后面,则不会报错,可以正确提取出字段。sql语句变为:select Field1,Field2,Feild3…… from TableName.

后来又测试了下,发现对如果是对decimal字段类型进行排序时,也会报这个错。

 

  相关解决方案