Methods Summary |
---|
public static java.sql.Connection | createConnection(java.lang.String db_driver, java.lang.String db_url, java.lang.String db_user, java.lang.String db_password)
// Load the database driver
System.out.println("Loading driver " + db_driver);
Class.forName(db_driver);
System.out.println("Connecting to DB " + db_url);
return DriverManager.getConnection(
db_url, db_user, db_password);
|
public static java.lang.String | getConfigFileName()Returns the full path of the configuration file being used.
return configFileName;
|
public static java.sql.Connection | getConnection(java.lang.String config)Get a Connection for the given config using the default or set property file name
try {
Properties p = new Properties();
p.load(new FileInputStream(configFileName));
return getConnection(p, config);
} catch (IOException ex) {
throw new DataBaseException(ex.toString());
}
|
public static java.sql.Connection | getConnection(java.util.Properties p, java.lang.String config)Get a Connection for the given config name from a provided Properties
try {
String db_driver = p.getProperty(config + "." + "DBDriver");
String db_url = p.getProperty(config + "." + "DBURL");
String db_user = p.getProperty(config + "." + "DBUser");
String db_password = p.getProperty(config + "." + "DBPassword");
if (db_driver == null || db_url == null) {
throw new IllegalStateException("Driver or URL null: " + config);
}
return createConnection(db_driver, db_url, db_user, db_password);
} catch (ClassNotFoundException ex) {
throw new DataBaseException(ex.toString());
} catch (SQLException ex) {
throw new DataBaseException(ex.toString());
}
|
public static void | setConfigFileName(java.lang.String configFileNam)Sets the full path of the config file to read.
configFileName = configFileNam;
File file = new File(configFileName);
if (!file.canRead()) {
throw new IllegalArgumentException("Unreadable: " + configFileName);
}
try {
ConnectionUtil.configFileName = file.getCanonicalPath();
} catch (IOException ex) {
System.err.println("Warning: IO error checking path: " + configFileName);
ConnectionUtil.configFileName = configFileName;
}
|