public boolean add(writeFrom frm)
{
String sql="insert into exam_write (ID_RUBRIC,TITLE,TITLE_A,TITLE_B,TITLE_C,TITLE_D,DA) values(?,?,?,?,?,?,?)";
boolean b=false;
Connection conn = ConnectionFactory.newInstance().getConnection();
   if(conn == null){
            return b;
        }
PreparedStatement stmt = null;
try
{

stmt = conn.prepareStatement(sql);
stmt.setString(1, frm.getID_RUBRIC());
stmt.setString(2, frm.getTITLE());
stmt.setString(3, frm.getTITLE_A());
stmt.setString(4, frm.getTITLE_B());
stmt.setString(5, frm.getTITLE_C());
stmt.setString(6, frm.getTITLE_D());
stmt.setString(7, frm.getDA());
b=stmt.execute();
}catch (SQLException ex) {
            ex.printStackTrace();
        }
 if(stmt != null){
            try {
                stmt.close();
            } catch (SQLException ex1) {
                ex1.printStackTrace();
            }
            stmt = null;
        }
        if(conn != null){
            try {
             conn.close();
            } catch (SQLException ex2) {
                ex2.printStackTrace();
            }
            conn = null;
        }
        return b;
}

解决方案 »

  1.   

    正常的啊,execute只有在执行后返回结果集的情况才返回true,如果你要检测是否插入成功,应该调用int result = stmt.executeUpdate(),这个方法返回的是sql调用影响的行数,如果插入成功,应该返回的是1
      

  2.   

    将SQL 打印出来就知道哪里错了
      

  3.   

    谢谢,我试一下,还有,我每次调用的时候,有的时候会帮我自动插入2条记录,结果就主键报错,我的调用没有写在循环里,是不是插入代码写的有BUG
      

  4.   

    看程序没什么问题,不过建议关闭的程序写到finally中去
      

  5.   

    楼上正解 
    加分吗!管理->分值操作->输入密码->确认 OK 呵呵