当前位置:Gxlcms > 数据库问题 > JDBC

JDBC

时间:2021-07-01 10:21:17 帮助过:2人阅读

public static Connection getConnection() throws Exception {
        // 1. ???????????? 4 ?????.
        // 1). ???? Properties ????
        Properties properties = new Properties();

        // 2). ??? jdbc.properties ???????????
        InputStream in = JDBCTools.class.getClassLoader().getResourceAsStream(
                "jdbc.properties");

        // 3). ???? 2?? ???????????
        properties.load(in);

        // 4). ??????? user, password ??4 ?????.
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String jdbcUrl = properties.getProperty("jdbcUrl");
        String driver = properties.getProperty("driver");

        // 2. ?????????????(????? Driver ??????????????????????.)
        Class.forName(driver);

        // 3. ??? DriverManager ?? getConnection() ???????????????.
        return DriverManager.getConnection(jdbcUrl, user, password);
    }

JDBC

标签:

人气教程排行