import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
public class Updata {
public static void main(String[] args) throws Exception {
String driverName = "com.mysql.cj.jdbc.Driver";
String userName = "root";
String userPwd = null;
String dbName = "students";
String url = "jdbc:mysql://localhost:3306/" + dbName + "?useSSL=false&serverTimezone=UTC";
Class.forName(driverName);
Connection conn = DriverManager.getConnection(url, userName, userPwd);
if (!conn.isClosed())
System.out.println("Succeeded connecting to the Database!");
Statement stmt = conn.createStatement();
String sql = "update stu set cj=? where xh=3";
PreparedStatement pstmt = conn.prepareStatement(sql);
int n = stmt.executeUpdate(sql);
if (n > 0) {
System.out.println("修改记录成功,共修改了" + n + "条记录");
} else {
System.out.println("修改不成功!");
}
pstmt.close();
stmt.close();
conn.close();
}
}