Sybase報Invalid packet type 0x22錯誤解決
今天使用Sybase(15.7 Developer版)查詢DB時,遇到了很詭異的錯誤,錯誤異常如下:
[java] www.2cto.com
<span style="font-size:12px;"><-- 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
</span>
經過定位,最終發現是指定的表中的字段個數太多(我這個表中有575個字段),把sql語句
修改成select 字段1,字段2 …… from 表
問題不再重現。
select * 時,底層雖然也會提取所有字段,但是會報這個錯誤,如果我們把所有字段列
在select後面,則不會報錯,可以正確提取出字段。sql語句變為:select Field1,Field2,
Feild3…… from TableName.
後來又測試了下,發現對如果是對decimal字段類型進行排序時,也會報這個錯。