day45-JDBC和连接池01( 四 )


//方式5 在方式4的基础上使用配置文件 , 连接数据库更加灵活@Testpublic void connect05() throws Exception {//通过Properties对象拿到配置文件的信息Properties properties = new Properties();properties.load(new FileInputStream("src\\mysql.properties"));//获取相关的值String user = properties.getProperty("user");String password = properties.getProperty("password");String url = properties.getProperty("url");String driver = properties.getProperty("driver");Class.forName(driver);//建议写上Connection connection = DriverManager.getConnection(url, user, password);System.out.println("方式5="+connection);}【day45-JDBC和连接池01】

经验总结扩展阅读