1.新建lib文件夹,将jar文件导入
2在structure中添加jar文件
3设置url时需要设置时区;
import java.sql.Connection;import java.sql.DriverManager;import java.sql.Statement;public class test01 { public static void main(String[] args) throws Exception {// 1导入jar包// 注册驱动 Class.forName("com.mysql.cj.jdbc.Driver");// 获取数据库连接 Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/ab?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false","root","");// 4定义SQL语句 String sql="update employ01 set salary=500 where id=1";// 5获取执行SQL对象; Statement statement=connection.createStatement();// 6执行SQL语句 int count=statement.executeUpdate(sql);// 7处理结果 System.out.println(count);// 释放资源 statement.close(); connection.close(); }}
来源:https://www.cnblogs.com/Damocless/p/11961841.html