// 注册驱动 mysql8.0.16
System.out.println("开始注册驱动");
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("注册成成功");
// 测试连接
System.out.println("开始获取连接对象");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db4?useSSL=false&serverTimezone=UTC", "root", "123456");
System.out.println("连接成功");
// 这些测试可以看出来哪里出错了,可以不要.但是要注意,db4是我的数据库名,root和123456是我的用户名和密码
// 这里是个演示,更新student表中的信息
String sql="update student set phone=55555 where id=3";
Statement statement = conn.createStatement();
int count = statement.executeUpdate(sql);
System.out.println(count);
statement.close();
conn.close();