关于bbs发表主贴问题

huxinxinxin 2012-04-24 11:29:13
发表主贴时,我设置的id号是自动递增的。我发表主贴时,要想使rootid等于新产生的id号,我该如何写代码啊?(注:id号设置是not null)。
Connection conn=DB.getconn();
String sql = "insert into article values (null, ?, ?, ?, ?, now(), ?)";
PreparedStatement pstmt = DB.prepareStmt(conn, sql, Statement.RETURN_GENERATED_KEYS);
pstmt.setInt(1,0);
pstmt.setInt(2,rootid);
pstmt.setString(3,title);
pstmt.setString(4,cont);
pstmt.setInt(5,0);
pstmt.executeUpdate();
ResultSet rekey=pstmt.getGeneratedKeys();
rekey.next();
rootid=rekey.getInt(1);


Statement stmt=DB.createStmt(conn);
stmt.executeUpdate("Update article set rootid="+rootid+ "where id="+rootid);
DB.close(stmt);
DB.close(pstmt);
DB.close(conn);
response.sendRedirect("article.jsp");
}
求高手进来解答啊
...全文
165 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
001007009 2012-04-25
  • 打赏
  • 举报
回复
用存储过程来返回
要么再用个sql来获取id
huxinxinxin 2012-04-25
  • 打赏
  • 举报
回复
用存储过程来返回
但得不到它的ID号啊。如何返回啊?呵呵,求指导啊。。。。

10,612

社区成员

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

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