当前位置: 代码迷 >> Java Web开发 >> JSP 发表新主题总报错!
  详细解决方案

JSP 发表新主题总报错!

热度:7381   发布时间:2013-02-25 21:15:53
JSP 发表新主题总报错求助!!
Java code
create sequence seq_article increment by 1 start with 1;create table article(id int primary key not null,pid int,rootid int,title varchar2(255),cont varchar2(4000),pdate date,isleaf int);insert into article (id,pid,rootid,title,cont,pdate,isleaf) values(seq_article.nextval, 0,1,'你好','大家好',sysdate,1);

这是往数据库里插入数据时的语句,设置id号是自动增加的
Java code
<%@page pageEncoding="UTF-8"%><%@page import="java.sql.*,bbs.*"%><%    request.setCharacterEncoding("UTF-8");    String action = request.getParameter("action");    if (action != null && action.trim().equals("post")) {        String title = request.getParameter("title");        //System.out.println(title);        String cont = request.getParameter("cont");        //System.out.println(cont);        Connection conn = DB.getConn();        boolean autoCommit = conn.getAutoCommit();        conn.setAutoCommit(false);                String sql = "insert into article values(seq_article.nextval,?,?,?,?,sysdate,?)";        PreparedStatement pstmt = DB.prepareStmt(conn, sql,Statement.RETURN_GENERATED_KEYS);        pstmt.setInt(1, 0);        pstmt.setInt(2, 1);        pstmt.setString(3, title);        pstmt.setString(4, cont);        pstmt.setInt(5, 0);        pstmt.executeUpdate();                ResultSet rsKey = pstmt.getGeneratedKeys();            rsKey.next();                int rootId= rsKey.getInt(1);        Statement stmt = DB.createStmt(conn);        stmt.executeUpdate("update article set rootid=" + rootId + " where id="+ rootId);        conn.commit();        conn.setAutoCommit(autoCommit);        DB.close(stmt);        DB.close(pstmt);        DB.close(conn);        response.sendRedirect("article.jsp");    }%>

这是发表新主题的页面,提交的时候提示int rootId= rsKey.getInt(1);这一句出错
错误提示:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:519)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

javax.servlet.ServletException: java.sql.SQLException: 无效的列类型: getInt not implemented for class oracle.jdbc.driver.T4CRowidAccessor
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.post_jsp._jspService(post_jsp.java:240)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
在网上查了一下,说ORACLE中 getGeneratedKeys() 拿不到sequence 的nextval,但不知道怎么改。。。。~~~~~
 

------解决方案--------------------------------------------------------
int rootId= rsKey.getInt(0)吧
------解决方案--------------------------------------------------------
如果实在不行的话,你就先去 "select seq_article.nextval from dual" 一下,把这个值接收一下,再来用。
最好的办法就是写个触发器,那么这里你就不需要你去手动指定了。
------解决方案--------------------------------------------------------
http://hi.baidu.com/mars_mars/blog/item/981193ccc68a915b0fb3459e
  相关解决方案