- Java code
<%@ page language="java" import="java.util.*,java.sql.*,bbs.*" pageEncoding="GB18030"%><% request.setCharacterEncoding("UTF-8"); int pid = Integer.parseInt(request.getParameter("pid")); int rootId = Integer.parseInt(request.getParameter("rootId")); String title = request.getParameter("title"); System.out.println(title); String cont = request.getParameter("cont"); System.out.println(cont); Connection conn = DB.getConn(); String sql = "insert into article values(null,?,?,?,?,sysdate,?)"; PreparedStatement pstmt = DB.prepareStmt(conn, sql); pstmt.setInt(1, pid); pstmt.setInt(2, rootId); pstmt.setString(3, title); pstmt.setString(4, cont); pstmt.setInt(5, 0); pstmt.executeUpdate(); DB.close(pstmt); DB.close(conn);%>
----------------------------------------------
数据已经能够提交,可是查询数据库发现其中的ID显示的是NULL,insert into article values(ID,pid,rootid,title,cont,pdate,isleaf) ID号不是从上一个页面传过来的不用自己设置的嘛
------解决方案--------------------------------------------------------
String sql = "insert into article values(null,?,?,?,?,sysdate,?)";你的ID是不是自增的,如果是自增的话,把null去掉
------解决方案--------------------------------------------------------
如果不是自增的 你添加null 数据库当然是null咯