Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class DAO {
- protected Connection myConn;
- public DAO() throws Exception {
- final String DB_DRIVER = "oracle.jdbc.driver.OracleDriver";
- // get database properties
- Properties props = new Properties();
- props.load(new FileInputStream("local.properties"));
- String user = props.getProperty("user");
- String password = props.getProperty("password");
- String dburl = props.getProperty("dburl");
- Class.forName(DB_DRIVER);
- // connect to database
- myConn = DriverManager.getConnection(dburl, user, password);
- System.out.println("DB connection succesful to: " + dburl);
- }
- protected static void close(Connection myConn, Statement myStmt,
- ResultSet myRs) throws SQLException {
- if (myRs != null) {
- myRs.close();
- }
- if (myStmt != null) {
- }
- if (myConn != null) {
- myConn.close();
- }
- }
- protected void close(Statement myStmt, ResultSet myRs) throws SQLException {
- close(null, myStmt, myRs);
- }
- public static void close(Statement myStmt) throws SQLException {
- close(null, myStmt, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement