连接数据库代码 新
private static DruidDataSource druidDataSource; static { Properties properties = new Properties(); InputStream inputStream = DButil.class.getResourceAsStream("/datebase.properties"); try { properties.load(inputStream); try { druidDataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties); } catch (Exception e) { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } } public static Connection getconnection() { try { return druidDataSource.getConnection(); } catch (SQLException e) { e.printStackTrace(); } return null; } public static void closeAll(Connection connection, Statement statement, ResultSet resultSet) { try { if(resultSet != null) resultSet.close(); if(statement != null) statement.close(); if(connection != null) connection.close(); } catch (SQLException e) { e.printStackTrace(); } }