//基于DriverManager 的获取数据库链接 String user = null; String password = null; String jdbcUrl = null; String driverClass = null; //获取配置文件 InputStream inputStream = getClass().getClassLoader().getResourceAsStream("jdbc.properties"); //读取文件 Properties properties = new Properties(); properties.load(inputStream);//载入文件 user = properties.getProperty("user"); password = properties.getProperty("password"); jdbcUrl = properties.getProperty("jdbcUrl"); driverClass = properties.getProperty("driver"); //注册数据库驱动程序员 Class.forName(driverClass); Connection connection = DriverManager.getConnection(jdbcUrl, user, password); return connection;