jsp代码插入问题,总是插入不进去,我写的是一个bbs的回复功能,高手帮忙啊?

来源:百度知道 编辑:UC知道 时间:2024/07/04 02:41:43
<%int id=Integer.parseInt(request.getParameter("id"));
int rootid=Integer.parseInt(request.getParameter("rootid"));
String cont=request.getParameter("cont");
String username=(String)session.getAttribute("username");
%>
<%
Connection conn=DB.getCon();
conn.setAutoCommit(false);
String sql="insert into article (`id` ,`username` ,`pid` , `rootid` ,`title` ,`cont` ,`pdate` ,`isleaf`) values(null,?,?,?,null,?,now(),0)";
PreparedStatement pstmt=DB.getPrepareStatement(conn,sql);
Statement stmt=DB.getStatement(conn);

pstmt.setString(1,username);
pstmt.setInt(2,id);
pstmt.setInt(3,rootid);
pstmt.setString(4,cont);
pstmt.executeUpdate();

stmt.executeUpdate("update article set isleaf=1 where id=" + id);
System.out.print("here execute");
conn.commit();
conn.setAutoCommit(true);
stmt

你日期的错误吧,now()如果不行,
你不要插入null试试,insert into table(要插入的列,不要都写上)

是不是pstmt.setString(1,"username");这样才对,字段名好像都要加一下引号