--- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Sat Jan 11 18:37:57 2014 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Wed Jan 15 18:15:55 2014 +0100
@@ -125,6 +125,9 @@
case Tokens.INFO_VERSION:
options.addShowInfo(InfoType.VERSION);
break;
+ case Tokens.INFO_JDBC_DRIVERS:
+ options.addShowInfo(InfoType.JDBC_DRIVERS);
+ break;
case Tokens.INFO_DATABASES:
options.addShowInfo(InfoType.DATABASES);
break;
@@ -166,6 +169,7 @@
public static final String INFO_LICENSE = "--license"; // bash-completion:option // help: print license
public static final String INFO_FORMATTERS = "--list-formatters"; // bash-completion:option // help: print list of available formatters
public static final String INFO_TYPES = "--list-types"; // bash-completion:option // help: print list of available data types
+ public static final String INFO_JDBC_DRIVERS = "--list-jdbc-drivers"; // bash-completion:option // help: list of available JDBC drivers
public static final String INFO_DATABASES = "--list-databases"; // bash-completion:option // help: print list of configured databases
public static final String INFO_CONNECTION = "--test-connection"; // bash-completion:option // help: test connection to particular database
--- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Jan 11 18:37:57 2014 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Wed Jan 15 18:15:55 2014 +0100
@@ -29,10 +29,12 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
+import java.sql.Driver;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
+import java.util.ServiceLoader;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.rowset.RowSetMetaDataImpl;
@@ -64,6 +66,7 @@
for (InfoType infoType : commands) {
switch (infoType) {
case CONNECTION:
+ case JDBC_DRIVERS:
case DATABASES:
case FORMATTERS:
case TYPES:
@@ -148,6 +151,29 @@
printTable(formatter, header, data);
}
+ public void listJdbcDrivers() throws FormatterException, ConfigurationException {
+ ColumnsHeader header = constructHeader(
+ new HeaderField("class", SQLType.VARCHAR),
+ new HeaderField("version", SQLType.VARCHAR),
+ new HeaderField("major", SQLType.INTEGER),
+ new HeaderField("minor", SQLType.INTEGER),
+ new HeaderField("jdbc_compliant", SQLType.BOOLEAN));
+ List<Object[]> data = new ArrayList<>();
+
+ final ServiceLoader<Driver> drivers = ServiceLoader.load(Driver.class);
+ for (Driver d : drivers) {
+ data.add(new Object[]{
+ d.getClass().getName(),
+ d.getMajorVersion() + "." + d.getMinorVersion(),
+ d.getMajorVersion(),
+ d.getMinorVersion(),
+ d.jdbcCompliant()});
+ }
+
+ printTable(formatter, header, data);
+
+ }
+
public void testConnection() throws FormatterException, ConfigurationException {
ColumnsHeader header = constructHeader(
new HeaderField("database_name", SQLType.VARCHAR),
@@ -287,6 +313,12 @@
infoLister.listTypes();
}
},
+ JDBC_DRIVERS {
+ @Override
+ public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException {
+ infoLister.listJdbcDrivers();
+ }
+ },
DATABASES {
@Override
public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {