日期:2014-05-17 浏览次数:21169 次
<%@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(); //System.out.print(rsKey); 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 = -1; if(rsKey.next()){ rootId= rsKey.getInt(1); }
------解决方案--------------------
1.你这是什么版本的驱动,class12.jar和ojdbc14.jar都不支持Statement.getGeneratedKeys方法
2.反编译看了一下,T4CRowidAccessor这个类没有getInt方法,你用getString方法试一试
------解决方案--------------------