JDBC1 --- 获取数据库连接的方式一 --- 技术搬运工(尚硅谷)

需要mysql-connector-java-5.1.7-bin.jar

@Test
    public void testConnection1() throws SQLException {
        Driver driver = new com.mysql.jdbc.Driver();
        
        /*
         * jdbc:主协议
         * mysql:子协议
         * localhost:ip
         * 3306:端口
         * test:数据库名
         */
        String url = "jdbc:mysql://localhost:3306/test";
        
        /*
         * 封装数据库的用户名和密码
         * Normally at least a "user" and"password" property should be included.
         */
        Properties info = new Properties();
        info.setProperty("user", "root");
        info.setProperty("password", "123456");
        
        Connection connect = driver.connect(url, info);
        System.out.println(connect);
    }

猜你喜欢

转载自www.cnblogs.com/noyouth/p/11731794.html