public class JDBCUtils { private static Connection connection; static { try { Properties properties = new Properties(); properties.load(new FileReader("src\\mysql.properties")); String url = properties.getProperty("url"); String user = properties.getProperty("user"); String pwd = properties.getProperty("pwd"); connection = DriverManager.getConnection(url, user, pwd); } catch (IOException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } public static Connection getConnection(){ return connection; } public static boolean Close(ResultSet resultSet, PreparedStatement statement,Connection connection){ try { if(resultSet != null){ resultSet.close(); } if(statement!=null){ statement.close(); } if(connection!=null){ connection.close(); } } catch (SQLException e) { e.printStackTrace(); } return true; } }
注意:静态方法只能使用静态属性,但是普通方法既能使用静态属性,又能使用非静态属性。
标签:jdbc,封装,printStackTrace,connection,static,close,工具,null,properties From: https://www.cnblogs.com/zwgitOne123/p/17077353.html