Advertisement
Guest User

Untitled

a guest
Jun 15th, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. public abstract class DAO {
  2.  
  3.     protected Connection myConn;
  4.  
  5.     public DAO() throws Exception {
  6.        
  7.         final String DB_DRIVER = "oracle.jdbc.driver.OracleDriver";
  8.        
  9.         // get database properties
  10.         Properties props = new Properties();
  11.         props.load(new FileInputStream("local.properties"));
  12.  
  13.         String user = props.getProperty("user");
  14.         String password = props.getProperty("password");
  15.         String dburl = props.getProperty("dburl");
  16.        
  17.         Class.forName(DB_DRIVER);
  18.  
  19.         // connect to database
  20.         myConn = DriverManager.getConnection(dburl, user, password);
  21.  
  22.         System.out.println("DB connection succesful to: " + dburl);
  23.     }
  24.  
  25.     protected static void close(Connection myConn, Statement myStmt,
  26.             ResultSet myRs) throws SQLException {
  27.  
  28.         if (myRs != null) {
  29.             myRs.close();
  30.         }
  31.  
  32.         if (myStmt != null) {
  33.  
  34.         }
  35.  
  36.         if (myConn != null) {
  37.             myConn.close();
  38.         }
  39.     }
  40.  
  41.     protected void close(Statement myStmt, ResultSet myRs) throws SQLException {
  42.         close(null, myStmt, myRs);
  43.     }
  44.    
  45.     public static void close(Statement myStmt) throws SQLException {
  46.         close(null, myStmt, null);     
  47.     }
  48.    
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement