JDBC -Utils
1 public class JDBCUtils { 2 3 public static Connection getConnection() throws Exception { 4 InputStream is = ClassLoader.getPlatformClassLoader().getResourceAsStream("jdbc.properties"); 5 Properties properties = new Properties(); 6 properties.load(is); 7 8 String user = properties.getProperty("user"); 9 String password = properties.getProperty("password"); 10 String url = properties.getProperty("url"); 11 String driverClass = properties.getProperty("driverClass"); 12 // Load the driver 13 Class.forName(driverClass); 14 15 Connection conn = DriverManager.getConnection(url, user, password); 16 17 return conn; 18 } 19 20 public static void closeConnect(Connection conn, Statement statement) { 21 try { 22 if (conn != null) 23 conn.close(); 24 } catch (SQLException throwables) { 25 throwables.printStackTrace(); 26 } 27 try { 28 if (statement != null) 29 statement.close(); 30 } catch (SQLException throwables) { 31 throwables.printStackTrace(); 32 } 33 } 34 }