时间:2021-07-01 10:21:17 帮助过:2人阅读
输入文件名和扩展名(.properties)
private static String driverClass = "" ; private static String url = "" ; private static String user = "" ; private static String password = ""; static{ ResourceBundle rb = ResourceBundle.getBundle("dbcfg") ; driverClass = rb.getString("driverClass") ; url = rb.getString("url") ; user = rb.getString("user") ; password = rb.getString("password") ; try { Class.forName(driverClass) ;//自动注册驱动 } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static Connection getConnection(){ try { return DriverManager.getConnection(url, user, password) ; } catch (SQLException e) { e.printStackTrace(); } return null ; }
JDBC 创建连接对象的三种方式
标签: