JDBC连接mysql8.0

JDBC连接mysql8.0

package com.ann.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcDemo01 {
    
    
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
    
    
        // 1.导入到驱动jar包
        // 2.注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 3.获取数据库连接对象
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC", "root", "password");
        // 4.定义sql语句
        String sql= "update tb_ware set price = 123 where id = 1";
        // 5.获取执行SQL的对象 Statement
        Statement statement = conn.createStatement();
        // 6.执行sql
        int count = statement.executeUpdate(sql);
        System.out.println(count);
        // 7.关闭连接
        conn.close();


    }
}

猜你喜欢

转载自blog.csdn.net/weixin_44121790/article/details/113141834