程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SyBase數據庫 >> SyBase教程 >> SybSQLException: The datastream for token 236 should only

SybSQLException: The datastream for token 236 should only

編輯:SyBase教程

運行以下程序是總是拋出一個異常:
Caused by: com.sybase.jdbc3.jdbc.SybSQLException: The datastream for token 236 should only be sent after other datastreams. It can not be a command datastream on it's own. This is an internal error.

具體方法為:
public List<?> executeProcedure(Class<?> entityClass, String procedure,
String requestId) {
List<?> list = new ArrayList<HibernateProcedureObject>();
try {
session = getCurrentSession(entityClass);
SQLQuery query = session.createSQLQuery(procedure);
query.setString(0, requestId);
list = query.list();
} catch (HibernateException e) {
e.printStackTrace();
logger.log(RMTManagementLevel.ERROR, e);
} finally {
this.closeConnection();
}
return list;

異常為:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2536)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
at com.eagle.utils.hibernatePersistence.HibernateSessionFactory.executeProcedure(HibernateSessionFactory.java:245)
at com.eagle.utils.hibernatePersistence.Test.testAuctionData_Procedure(Test.java:498)
at com.eagle.utils.hibernatePersistence.Test.main(Test.java:512)
Caused by: com.sybase.jdbc3.jdbc.SybSQLException: The datastream for token 236 should only be sent after other datastreams. It can not be a command datastream on it's own. This is an internal error.

at com.sybase.jdbc3.tds.Tds.processEed(Tds.java:2942)
at com.sybase.jdbc3.tds.Tds.nextResult(Tds.java:2246)
at com.sybase.jdbc3.tds.Tds.getResultSetResult(Tds.java:2853)
at com.sybase.jdbc3.tds.TdsCursor.open(TdsCursor.java:295)
at com.sybase.jdbc3.jdbc.SybStatement.executeQuery(SybStatement.java:1659)
at com.sybase.jdbc3.jdbc.SybPreparedStatement.executeQuery(SybPreparedStatement.java:97)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
at org.hibernate.loader.Loader.doQuery(Loader.java:802)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:2533)
... 9 more

解決方案:
只能利用傳統的Connection和ResultSet的形式:
resultSet = null;
try {
cstmt = getCurrentSession(entityClass).connection().prepareCall(
"{call " + procedure + "}");
resultSet = cstmt.executeQuery();
} catch (HibernateException e) {
this.closeConnection();
e.printStackTrace();
logger.log(RMTManagementLevel.ERROR, e);
} catch (SQLException e) {
this.closeConnection();
e.printStackTrace();
logger.log(RMTManagementLevel.ERROR, e);
}

作者“來杯咖啡,隨便聊聊。”
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved