Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface ConnectionDB {
- public Connection getConnection();
- }
- public class GenericConnection {
- protected static Properties dbProperties = new Properties();
- public static Properties getDbProperties() {
- if(dbProperties == null){
- try {
- dbProperties.load(new FileInputStream("src/properties/conf.properties"));
- } catch (FileNotFoundException ex) {
- Logger.getLogger(GenericConnection.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(GenericConnection.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- return dbProperties;
- }
- public static void setDbProperties(Properties dbProperties) {
- GenericConnection.dbProperties = dbProperties;
- }
- }
- public class OracleConnection extends GenericConnection implements ConnectionDB {
- private Connection conn;
- private Statement st;
- public Statement getSt() {
- return st;
- }
- public void setSt(Statement st) {
- this.st = st;
- }
- public Connection getConn() {
- return conn;
- }
- public void setConn(Connection conn) {
- this.conn = conn;
- }
- @Override
- public Connection getConnection() {
- if (getConn() != null) {
- return getConn();
- } else {
- try {
- String url = "jdbc:oracle:thin:@" + getDbProperties().getProperty("ServerOracle") + ":" + getDbProperties().getProperty("portOracle") + ":" + getDbProperties().getProperty("sidOracle");
- setConn(DriverManager.getConnection(url, getDbProperties().getProperty("userOracle"), getDbProperties().getProperty("passwdOracle")));
- setSt(getConn().createStatement());
- return getConn();
- } catch (SQLException ex) {
- Logger.getLogger(OracleConnection.class.getName()).log(Level.SEVERE, null, ex);
- return null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement