为什么不能插入数据?
数据库是access,也没有抛出异常,但是数据是没有插入进去.
public void insert(Teacher t) {
Connection conn = null;
PreparedStatement pst = null;
String sql = "insert into Teacher (姓名 ,单位 ,部门 ," +
"办公电话 ,家里电话 ,手机 ,地址 ," +
"职位 ,生日 ,爱好 ,email ,QQ ," +
"MSN ,skype ,备注 ,first ,second, " +
"third ,forth ,fifth,编号) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
try{
conn = DBConnection.getConnection();
pst = conn.prepareStatement(sql);
pst.setString(1, t.getName());
pst.setString(2, t.getCompany());
pst.setString(3, t.getDepartment());
pst.setString(4, t.getOfficePhone());
pst.setString(5, t.getHomePhone());
pst.setString(6, t.getMovePhone());
pst.setString(7, t.getAddress());
pst.setString(8, t.getPosition());
pst.setString(9, t.getBirthday());
pst.setString(10, t.getHobby());
pst.setString(11, t.getEmail());
pst.setString(12, t.getQQ());
pst.setString(13, t.getMSN());
pst.setString(14, t.getSkype());
pst.setString(15, t.getRemark());
pst.setString(16, t.getFirst());
pst.setString(17, t.getSecond());
pst.setString(18, t.getThird());
pst.setString(19, t.getForth());
pst.setString(20, t.getFifth());
pst.setInt(21, t.getId());
pst.execute();
conn.commit();
System.out.println("execute ok");
}catch(Exception e){
e.printStackTrace();
}
}
在线等....