Skip to content

Commit

Permalink
Throwing informative error when connecting to wrong database
Browse files Browse the repository at this point in the history
  • Loading branch information
schuemie committed May 27, 2016
1 parent 4bb08e0 commit d279aa7
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/org/ohdsi/whiteRabbit/WhiteRabbitMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,17 @@ private void pickTables() {
RichConnection connection = new RichConnection(sourceDbSettings.server, sourceDbSettings.domain, sourceDbSettings.user,
sourceDbSettings.password, sourceDbSettings.dbType);
String tableNames = StringUtilities.join(connection.getTableNames(sourceDbSettings.database), "\t");
DBTableSelectionDialog selectionDialog = new DBTableSelectionDialog(frame, true, tableNames);
if (selectionDialog.getAnswer()) {
for (Object item : selectionDialog.getSelectedItems()) {
if (!tables.contains(item))
tables.add((String) item);
tableList.setListData(tables.toArray());
if (tableNames.length() == 0) {
JOptionPane.showMessageDialog(frame, "No tables found in database " + sourceDbSettings.database, "Error fetching table names",
JOptionPane.ERROR_MESSAGE);
} else {
DBTableSelectionDialog selectionDialog = new DBTableSelectionDialog(frame, true, tableNames);
if (selectionDialog.getAnswer()) {
for (Object item : selectionDialog.getSelectedItems()) {
if (!tables.contains(item))
tables.add((String) item);
tableList.setListData(tables.toArray());
}
}
}
connection.close();
Expand Down Expand Up @@ -737,7 +742,9 @@ private void testConnection(DbSettings dbSettings) {
}

try {
connection.getTableNames(dbSettings.database);
List<String> tableNames = connection.getTableNames(dbSettings.database);
if (tableNames.size() == 0)
throw new RuntimeException("Unable to retrieve table names for database " + dbSettings.database);
} catch (Exception e) {
String message = "Could not connect to database: " + e.getMessage();
JOptionPane.showMessageDialog(frame, StringUtilities.wordWrap(message, 80), "Error connecting to server", JOptionPane.ERROR_MESSAGE);
Expand Down

0 comments on commit d279aa7

Please sign in to comment.