数据库中信息的修改

代码示例:

import java.sql.*;

public class DeleteStu {
static Connection con;
static PreparedStatement sql;
static ResultSet res;
public Connection getConnection() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false&serverTimezone=GMT","root","020714");
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
public static void main(String[] args) {
DeleteStu c = new DeleteStu();
con = c.getConnection();
try {
sql = con.prepareStatement("delete from tb_stu where birthday < ?");
sql.setString(1, "2001-05-01");//删除出生日期在2001-05-01之前的学生
sql.executeUpdate();
System.out.println("数据删除完毕");
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}

}

原文地址:https://www.cnblogs.com/zhaoyuxiao000/p/14169499.html