Retrofitted the getConnection method to accept explicit connection props.
This commit is contained in:
parent
ef91212d4c
commit
104b0d597f
|
@ -15,18 +15,37 @@ public class JdbcConnectionUtil {
|
||||||
try {
|
try {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.load(JdbcConnectionUtil.class.getResourceAsStream("jdbc.properties"));
|
props.load(JdbcConnectionUtil.class.getResourceAsStream("jdbc.properties"));
|
||||||
Class.forName(props.getProperty("jdbc.driver"));
|
|
||||||
con = DriverManager.getConnection(props.getProperty("jdbc.url"), props.getProperty("jdbc.user"), props.getProperty("jdbc.password"));
|
String jdbcUrl = props.getProperty("jdbc.url");
|
||||||
|
String driver = props.getProperty("jdbc.driver");
|
||||||
|
String username = props.getProperty("jdbc.user");
|
||||||
|
String password = props.getProperty("jdbc.password");
|
||||||
|
con = getConnection(jdbcUrl, driver, username, password);
|
||||||
return con;
|
return con;
|
||||||
} catch (IOException exc) {
|
} catch (IOException exc) {
|
||||||
exc.printStackTrace();
|
exc.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return con;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Connection getConnection(String jdbcUrl, String driver, String username, String password) {
|
||||||
|
if (con == null) {
|
||||||
|
try {
|
||||||
|
Class.forName(driver);
|
||||||
|
con = DriverManager.getConnection(jdbcUrl, username, password);
|
||||||
|
return con;
|
||||||
} catch (ClassNotFoundException exc) {
|
} catch (ClassNotFoundException exc) {
|
||||||
exc.printStackTrace();
|
exc.printStackTrace();
|
||||||
} catch (SQLException exc) {
|
} catch (SQLException exc) {
|
||||||
exc.printStackTrace();
|
exc.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return con;
|
return con;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue