@Override
public boolean delete(UserModel user) {
Connection conn = null;
try{
conn = DBconn.getConn();
String sql = "delete from soctt.tb1_user where id=?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, user.getId());
System.out.println("Id1111111========"+user.getId());
pstmt.executeUpdate();
System.out.println("Id222222========"+user.getId());
pstmt.close();
}catch(Exception err){
err.fillInStackTrace();
}finally{
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return true;
}
这是我的代码,测试到pstmt.executeUpdate(); 这个语句不执行,删除不了数据JDBC没有问题,我的增加数据,显示数据
public boolean delete(UserModel user) {
Connection conn = null;
try{
conn = DBconn.getConn();
String sql = "delete from soctt.tb1_user where id=?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, user.getId());
System.out.println("Id1111111========"+user.getId());
pstmt.executeUpdate();
System.out.println("Id222222========"+user.getId());
pstmt.close();
}catch(Exception err){
err.fillInStackTrace();
}finally{
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return true;
}
这是我的代码,测试到pstmt.executeUpdate(); 这个语句不执行,删除不了数据JDBC没有问题,我的增加数据,显示数据
你显示的提交下 conn.commit();
pstmt.executeUpdate();后面的语句都没有执行包括System.out.println("Id222222========"+user.getId());
PS:如果没猜错的话如果不是数据库连接有误就应该是user.getId()报异常了
System.out.println("Id1111111========"+user.getId());
pstmt.executeUpdate();
System.out.println("Id222222========"+user.getId());这里出现问题,第一条输出在后台有,但第二条输出后台没有打印,判断应该是pstmt.executeUpdate();
没有执行,数据库没有删除数据
PS:调试好好学学 用print调试没觉得很麻烦么
catch(Exception err){
err.printStackTrace();
}
改成pstmt.setInt(1, user.getId());