1. 程式人生 > >2.MySQL8.0版本jdbc驅動連線資料庫操作

2.MySQL8.0版本jdbc驅動連線資料庫操作

1.JDBC操作資料庫的步驟:

    1.註冊驅動

        告知JVM使用的是哪一個資料庫的驅動;

    2.獲得連結

        使用JDBC中的類,完成對MySql資料庫的連結;

    3.獲得語句執行平臺

        通過連結物件獲取對SQL語句的執行者物件;

    4.執行sql語句

        使用執行者物件,向資料庫執行SQL語句,獲取到資料庫的執行後的結果;

    5.處理結果

    6.釋放資源  一堆close()

2.mysql8.0版本jdbc驅動jar包下載地址

3.mysql8.0版本以下配置

        //1.註冊驅動
        Class.forName("com.mysql.jdbc.Driver");
        //2.獲取連線
        String url ="jdbc:mysql80://localhost:3306/time";
        String username="root";//預設
        String password="****";//自己設定的密碼
        conn = DriverManager.getConnection(url,username,password);

4.mysql8.0配置

        //1.註冊驅動
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.獲取連線
        String url ="jdbc:mysql://localhost:3306/{自己設定的資料庫名}?useSSL=false&serverTimezone=UTC";
        String username="root";//預設
        String password="****";//自己設定的密碼
        conn = DriverManager.getConnection(url,username,password);