1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Thu Dec 26 01:05:24 2013 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Thu Dec 26 01:24:21 2013 +0100
1.3 @@ -17,10 +17,13 @@
1.4 */
1.5 package info.globalcode.sql.dk;
1.6
1.7 +import info.globalcode.sql.dk.configuration.ConfigurationException;
1.8 import info.globalcode.sql.dk.configuration.ConfigurationProvider;
1.9 +import info.globalcode.sql.dk.configuration.DatabaseDefinition;
1.10 import java.io.BufferedReader;
1.11 import java.io.InputStreamReader;
1.12 import java.io.PrintStream;
1.13 +import java.sql.SQLException;
1.14 import java.util.EnumSet;
1.15 import java.util.logging.Level;
1.16 import java.util.logging.Logger;
1.17 @@ -67,7 +70,22 @@
1.18 println("TODO: list databases");
1.19 break;
1.20 case CONNECTION:
1.21 - println("TODO: test database connection: " + options.getDatabaseNameToTest());
1.22 + boolean connectionTestResult = false;
1.23 + String dbName = options.getDatabaseNameToTest();
1.24 + log.log(Level.FINE, "Testing connection to database: {0}", dbName);
1.25 + try {
1.26 + DatabaseDefinition dd = configurationProvider.getConfiguration().getDatabase(dbName);
1.27 + if (dd == null) {
1.28 + log.log(Level.SEVERE, "No database with this name is configured: {0}", dbName);
1.29 + } else {
1.30 + log.log(Level.FINE, "Database definition was loaded from configuration");
1.31 + DatabaseConnection dc = dd.connect();
1.32 + connectionTestResult = dc.test();
1.33 + }
1.34 + } catch (ConfigurationException | SQLException e) {
1.35 + log.log(Level.SEVERE, "Error during testing connection", e);
1.36 + }
1.37 + log.log(Level.INFO, "Connection test result: {0}", connectionTestResult ? "success" : "failure");
1.38 break;
1.39 default:
1.40 throw new IllegalArgumentException("Unsupported INFO_TYPE: " + infoType);