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;
}
------解决方案--------------------
正常的啊,execute只有在执行后返回结果集的情况才返回true,如果你要检测是否插入成功,应该调用int result = stmt.executeUpdate(),这个方法返回的是sql调用影响的行数,如果插入成功,应该返回的是1
------解决方案--------------------
将SQL 打印出来就知道哪里错了
------解决方案--------------------
看程序没什么问题,不过建议关闭的程序写到finally中去