10月23日学习日志

今天学习了Java数据库操作的删除数据的方法。

代码如:

public static int delete(String name) {
   Connection conn = getConn();
   int i = 0;
   String sql = "delete from students where Name='" + name + "'";
   PreparedStatement pstmt;
   try {
       pstmt = (PreparedStatement) conn.prepareStatement(sql);
       i = pstmt.executeUpdate();
       System.out.println("resutl: " + i);
       pstmt.close();
       conn.close();
   } catch (SQLException e) {
       e.printStackTrace();
   }
   return i;
} 

 

posted @ 2020-10-23 17:58  张笑天  阅读(38)  评论(0编辑  收藏  举报