10月24日学习日志

今天学习了Java数据库操作修改数据的方法。

代码如:

public static int update(Student student) {
   Connection conn = getConn();
   int i = 0;
   String sql = "update students set Age='" + student.getAge() + "' where Name='" + student.getName() + "'";
   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-24 15:59  张笑天  阅读(40)  评论(0编辑  收藏  举报