This section describes how to get some basic info about Java DB (Derby) and JDBC driver through the JDBC DatabaseMetaData object.
If you want to know the Java DB database name and version, or
the JDBC driver name and version, you can get them through the
DatabaseMetaData object as shown in the following sample program:
/**
* DerbyDatabaseInfo.java
* Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
*/
import java.sql.*;
public class DerbyDatabaseInfo {
public static void main(String [] args) {
Connection con = null;
try {
con = DriverManager.getConnection(
"jdbc:derby://localhost/TestDB");
// Database and driver info
DatabaseMetaData meta = con.getMetaData();
System.out.println("Server name: "
+ meta.getDatabaseProductName());
System.out.println("Server version: "
+ meta.getDatabaseProductVersion());
System.out.println("Driver name: "
+ meta.getDriverName());
System.out.println("Driver version: "
+ meta.getDriverVersion());
System.out.println("JDBC major version: "
+ meta.getJDBCMajorVersion());
System.out.println("JDBC minor version: "
+ meta.getJDBCMinorVersion());
con.close();
} catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
}
}
}
Here is the output of my test program:
C:\>javac DerbyDatabaseInfo.java
C:\>java -cp .;\local\javadb\lib\derbyclient.jar DerbyDatabaseInfo
Server name: Apache Derby
Server version: 10.2.2.0 - (485682)
Driver name: Apache Derby Network Client JDBC Driver
Driver version: 10.2.2.0 - (485682)
JDBC major version: 4
JDBC minor version: 0