public void connection_jdbc(){ try{ Properties prop = new Properties(); //编译打包完之后的classes下 如下图 InputStream is = this.getClass().getResourceAsStream("/resources/mysql_jdbc.properties"); //加载配置文件 prop.load(is); //获取连接信息 String user = prop.getProperty("user"); String password = prop.getProperty("password"); String url = prop.getProperty("url"); String driverClass = prop.getProperty("driverClass"); //加载驱动 Class.forName(driverClass); //获取连接 Connection connection = DriverManager.getConnection(url, user, password); }catch(Exception e){ e.printStackTrace(); } } ================================================================================ mysql_jdbc.properties user=root password=xxxxxxx url=jdbc:mysql://192.168.137.1:3306/learn?serverTimezone=UTC driverClass=com.mysql.cj.jdbc.Driver
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)