* not be successfully opened
*/
public static Connection getDBConnection(String dbName, String projName) {
ConnectionManager cMgr = ConnectionManager.getDefault();
DatabaseConnection[] dbconnList = cMgr.getConnections();
DatabaseConnection dbconn = null;
// find a connection for given database & project, if one exists
System.out.println("DBConnList size: " + dbconnList.length);
if (dbconnList.length > 0) {
for (DatabaseConnection con : dbconnList) {
String name = con.getDisplayName().toLowerCase();
System.out.println(con.getDisplayName());
if (name.contains(dbName) && name.contains(projName)) {
dbconn = con;
}
}
}
if (dbconn == null) {
// TODO: create a connection here if none found
return null;
} else {
System.out.println("Got db connection: " + dbconn.getName());
// System.out.println(" Driver: " + dbconn.getJDBCDriver().getName());
// System.out.println(" URL: " + dbconn.getDatabaseURL());
// System.out.println(" user: " + dbconn.getUser());
// System.out.println(" schema: " + dbconn.getSchema());
}
Connection connection = dbconn.getJDBCConnection();
if (connection == null) {
cMgr.showConnectionDialog(dbconn);
}
return connection;
}