JSP 发表新主题总报错求助!!

Summerle 2012-06-29 03:50:18

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号是自动增加的

<%@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,但不知道怎么改。。。。~~~~~
...全文
223 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
mesada_yangzaixing 2013-08-17
  • 打赏
  • 举报
回复
rs = ps.getGeneratedKeys(); rs.next(); String rowid= rs.getString(1);//获得rowid ps = conn.prepareStatement("select t.micrateruleid from T_MICRATE_RULE t where rowid = ?"); ps.setString(1, rowid); ResultSet rest2 = ps.executeQuery(); rest2.next(); id=Long.parseLong(rest2.getString(1));
Miracle_lucy 2013-08-04
  • 打赏
  • 举报
回复
出现了同样的问题,有贴个解决方法出来的吗
Summerle 2012-06-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

http://hi.baidu.com/mars_mars/blog/item/981193ccc68a915b0fb3459e.html
看看
用getLong试试
[/Quote]

改着改着我就晕了- -
Summerle 2012-06-29
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

http://hi.baidu.com/mars_mars/blog/item/981193ccc68a915b0fb3459e.html
看看
用getLong试试
[/Quote]
我试试..
Summerle 2012-06-29
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

http://hi.baidu.com/mars_mars/blog/item/981193ccc68a915b0fb3459e.html
看看
用getLong试试
[/Quote]
我试试..
风火轮 2012-06-29
  • 打赏
  • 举报
回复
http://hi.baidu.com/mars_mars/blog/item/981193ccc68a915b0fb3459e.html
看看
用getLong试试
johnny_ 2012-06-29
  • 打赏
  • 举报
回复
如果实在不行的话,你就先去 "select seq_article.nextval from dual" 一下,把这个值接收一下,再来用。
最好的办法就是写个触发器,那么这里你就不需要你去手动指定了。
Summerle 2012-06-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

int rootId= rsKey.getInt(0)吧
[/Quote]
不行,试过了
javax.servlet.ServletException: java.sql.SQLException: 无效的列索引
风火轮 2012-06-29
  • 打赏
  • 举报
回复
int rootId= rsKey.getInt(0)吧

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧