免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3329 | 回复: 2
打印 上一主题 下一主题

大家帮我看看 Function sequence error 的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-04 22:39 |只看该作者 |倒序浏览
我在 一个无状态会话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.prepareStatement(sql);
抛出 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:16
[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:59
[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:25
[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.

3.如果我把代码改写为如下,就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();
                        }
                }
        }

4.我以“Function sequence error”关键字搜索了一下,

发现前人遇到这样的问题,原因在于前一个RecordSet没有关闭,好像我的代码没有这样的问题啊!


高手来解答一下!多谢!

论坛徽章:
0
2 [报告]
发表于 2005-06-05 01:38 |只看该作者

大家帮我看看 Function sequence error 的问题

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);

你把labRS 关掉再看看
照理说你的ds.getConnection();应该从连接池里面取一个available的connection,而不是shared的connection,因为有时候你的确需要同时打开多个connection,你检查一下ds.getConnection()的实现是否有问题。

论坛徽章:
0
3 [报告]
发表于 2005-06-05 09:24 |只看该作者

大家帮我看看 Function sequence error 的问题

谢谢你的回复。

应该与labRS无关吧,LabResultSet是实现Serializable的一个类,
用来装ResultSet的数据并返回前台的。
class LabResultSet implements java.io.Serializable{
LabResultSet(ResultSet rs){
while(rs.next()
{
......//取数据
}
}
}


DataSource ds;
ds.getConnection()方法还能有什么问题呢?再说我在
queryDB()里面已经把resultset和connection都关闭了。

为什么用statement就可以呢?

高手请指点一下!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP