ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ package JDBC; /** * @author: hcf * @qq: 46914685 * @email: 46914685@qq.com */ import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; /** * JDBC 快速入门 */ public class JdbcDemo1 { public static void main(String[] args) throws Exception { //1.导入驱动jar包 //2.注册驱动 Class.forName("com.mysql.cj.jdbc.Driver"); //3.获取数据库连接对象 Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/db1?serverTimezone=UTC", "root", "admin123"); //4.定义sql语句 String sql = "update account set balance=589.99 where id=1"; //5.获取执行sql的对象 Statement Statement stmt = conn.createStatement(); //6执行sql int count = stmt.executeUpdate(sql); //7处理结果 System.out.println(count); //8.释放资源 stmt.close(); conn.close(); } } ~~~