大家帮我看看 Function sequence error 的问题
我在 一个无状态会话bean里写了这样一个方法:
/**
* 根据keyName来查询lakeyp的值,并加1更新
* 取流水号
*/
public int getKey(String keyName) throws SQLException, Exception {
Connection conn = null;
PreparedStatement pstmt = null;
LabResultSet labRS;
int result = -1;
try {
labRS =
queryDB(
"select kyvalu from ladta.lakeyp where kycode='"
+ keyName.trim()
+ "'");
if (labRS.recordcount > 0) {
result = labRS.get(0).getInt("kyvalu");
String sql ="update ladta.lakeyp set kyvalu=kyvalu+1 where kycode=?";
conn = ds.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,keyName.trim());
pstmt.execute(sql);
}
return result;
} catch (SQLException ex) {
ex.printStackTrace();
throw ex;
} finally {
if (pstmt != null) {
pstmt.close();
}
if (conn != null) {
conn.close();
}
}
}
结果总是运行到此语句时pstmt = conn.createStatement();抛出 Function sequence error错误,
这是为什么?
附:
1. queryDB方法,在同一bean定义
public LabResultSet queryDB(String sql) throws SQLException, Exception {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
errorCode = 0;
errorMsg = "";
try {
conn = ds.getConnection();
System.out.println("查询SQL:" + sql);
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
return new LabResultSet(rs);
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
} finally {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
if (conn != null) {
conn.close();
}
}
}
2. 完整的错误
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R java.sql.SQLException: Function sequence error.
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.as400.access.JDError.throwSQLException(JDError.java:305)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.as400.access.AS400JDBCPreparedStatement.execute(AS400JDBCPreparedStatement.java:725)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.execute(WSJdbcStatement.java:285)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.labor.query.QueryBean.getKey(QueryBean.java:151)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.labor.query.EJSRemoteStatelessQuery_3a34917c.getKey(EJSRemoteStatelessQuery_3a34917c.java:69)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.labor.query._Query_Stub.getKey(_Query_Stub.java:315)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at org.apache.jsp._track._jspService(_track.java:168)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:598)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:696)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:258)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.mcm.util.tools.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:119)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:863)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:491)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:173)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:199)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:331)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:432)
[05-6-4 11:10:38:359 CST] 750db18e SystemErr R at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:343)
[05-6-4 11:10:38:375 CST] 750db18e SystemErr R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:592)
[05-6-4 11:10:38:422 CST] 750db18e WebGroup E SRVE0026E: [Servlet 错误]-[Function sequence error.]:java.sql.SQLException: Function sequence error.
问题点数:100、回复次数:5Top
1 楼flai(飞飞)回复于 2005-06-04 11:29:00 得分 0
如果我把代码改写为如下,就OK了,二者的区别在于PreparedStatement与Statement,为什么??
开发环境:wsad5.0+DB2/400
public int getKey(String keyName) throws SQLException, Exception {
Connection conn = null;
Statement pstmt = null;
LabResultSet labRS;
int result = -1;
try {
labRS =
queryDB(
"select kyvalu from lakeyp where kycode='"
+ keyName.trim()
+ "'");
if (labRS.recordcount > 0) {
result = labRS.get(0).getInt("kyvalu");
String sql =
"update lakeyp set kyvalu=kyvalu+1 where kycode='"
+ keyName.trim()
+ "'";
conn = ds.getConnection();
pstmt = conn.createStatement();
pstmt.execute(sql);
}
return result;
} catch (SQLException ex) {
ex.printStackTrace();
throw ex;
} finally {
if (pstmt != null) {
pstmt.close();
}
if (conn != null) {
conn.close();
}
}
}Top
2 楼flai(飞飞)回复于 2005-06-04 11:31:17 得分 0
我在csdn里以“Function sequence error”关键字搜索了一下,
发现前人遇到这样的问题,原因在于前一个RecordSet没有关闭,好像我的代码没有这样的问题啊!
高手来解答一下!多谢!Top
3 楼flai(飞飞)回复于 2005-06-04 21:45:15 得分 0
自己顶一下!Top
4 楼goodsong(风卷残云~不要把简单的事搞得N复杂)回复于 2005-06-05 11:11:27 得分 100
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,keyName.trim());
pstmt.execute(sql);
改为
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,keyName.trim());
pstmt.executeUpdate();
试试Top
5 楼flai(飞飞)回复于 2005-06-06 09:51:14 得分 0
解决了,pstmt.execute(sql); 改成 pstmt.execute();或pstmt.executeUpdate();
因为PreparedStatement是extends自Statement,PreparedStatement本身是没有execute(String sql),
和executeUpdate(String ..)方法的,
pstmt.execute(sql);调的是其基类Statement的execute()方法,当然不行啰
哈哈
Top
相关问题
- DB2数据库,出现错误:CLI0125 Function Sequence Error. SQLSTATE=HY010
- 有关Function sequence的问题,谢谢
- 在线救助!在线送分!高手帮忙!error C2731: 'WinMain' : function cannot be overloaded
- error C2659: '=' : overloaded function as left operand
- Strange "Static Varable,Static Function " Link Error!
- Fatal error: Call to a member function on a non-object
- error C2660: 'new' : function does not take 3 parameters
- error: 'sub_max' : function does not take 2 parameters
- create sequence
- 请朋友们帮忙!Call to undefined function "IntPower"!




