1. 程式人生 > 其它 >&【02】Python 基礎語法

&【02】Python 基礎語法

一、匯入資料庫驅動到目錄

二、新增驅動到庫

三、連線資料庫

方式一:

public static void main(String[] args) throws SQLException {
        Driver driver = new com.mysql.jdbc.Driver();
        String url = "jdbc:mysql://localhost:3306/baizhan?useSSL=false";
        Properties info = new Properties();
        info.setProperty("user","root");
        info.setProperty("password","1234");
        Connection conn = driver.connect(url,info);
        System.out.println(conn);
    }

方式二:

public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException, NoSuchMethodException, InvocationTargetException {
        Class clazz = Class.forName("com.mysql.jdbc.Driver");
        Driver driver = (Driver)clazz.getDeclaredConstructor().newInstance();
        String url = "jdbc:mysql://localhost:3306/baizhan?useSSL=false";
        Properties info = new Properties();
        info.setProperty("user","root");
        info.setProperty("password","1234");
        Connection conn = driver.connect(url,info);
        System.out.println(conn);
    }