public void save(Emp emp) throws Exception {
Connection con=null;
PreparedStatement pstm=null;
String sql="insert into t_emp(sname,age,salary) values(?,?,?)";
try {
con=DBUtil.getConnection();
pstm=con.prepareStatement(sql);
pstm.setString(1, emp.getSname());
pstm.setInt(2, emp.getAge());
pstm.setDouble(3, emp.getSalary());
pstm.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
throw new Exception(e);
}finally{
DBUtil.closeConnection(con);
}
这段代码就是往数据库里面插入的代码,可是当我查数据的时候,显示的sname字段都是NULL,这是为什么啊。以前也用过这段代码,没问题啊,今天不知道为什么,插入不进去啊,郁闷 啊