Derby and JDBC version How-To

"Help! Which Derby version am I using?"

Table of Contents

Derby database format version

The Derby database format may change between Derby feature releases (for example 10.1.x -> 10.2.x -> 10.3.x), but will (most likely) not change between releases of the same branch (for example -> Thus, the database format version number will be either 10.0, 10.1, 10.2 or 10.3, etc.

Possible scenario: You want to start using some great new feature in the latest Derby release against your existing database, so you need to do a so-called "hard upgrade" of the database. You are not quite sure which version of Derby you were using when you created the database, which may be useful to know before upgrading.

Possible solution (1): Read the database property DataDictionaryVersion when the database is booted using the most recent JDBC driver version available to you.

Example: Use IJ and the embedded driver from to connect to your database ('tenOneThreeOne', created with the release) and retrieve the version number:

$ java -jar /opt/derby/ ij 
ij version 10.3
ij> connect 'jdbc:derby:tenOneThreeOne';
ij> values syscs_util.syscs_get_database_property( 'DataDictionaryVersion' );

Note that this property is not a documented part of Derby's api, so this could change in a future release.

Possible solution (2): Try booting the database using the oldest JDBC driver available to you. If the database format is newer and incompatible, an SQLException (or ij error) will be thrown, detailing the version of the database format.

Example: Use IJ and the embedded driver from to attempt a connection to your (hopefully newer) database.

$ java -cp /opt/derby/
ij version 10.0
ij> connect 'jdbc:derby:tenThreeOneFour';
ERROR XJ040: Failed to start database 'tenThreeOneFour', see the next exception for details.
ERROR XSLAN: Database at /opt/derby/databases/tenThreeOneFour has an incompatible format with the current version of the software.  The database was created by or upgraded by version 10.3.

Derby jar file version (sysinfo)

Possible scenario: You found out that you have a Derby installation on your hard drive, but you don't know which version it is.

Possible solution: Run sysinfo.

Example: If you have derbyrun.jar available (should be in the lib directory of Derby versions and later), you can do:

java -jar /home/user/derby/lib/derbyrun.jar sysinfo

In the above example, the Derby installation is located in the directory /home/user/derby/ on a Unix/Linux system, and the PATH points to a valid Java installation.

Look for something like this in your output, which will tell you the version of your derby jar files:

--------- Derby Information --------
JRE - JDBC: J2SE 5.0 - JDBC 3.0
[/home/user/derby/lib/derby.jar] - (561794)
[/home/user/derby/lib/derbytools.jar] - (561794)
[/home/user/derby/lib/derbynet.jar] - (561794)
[/home/user/derby/lib/derbyclient.jar] - (561794)

Here, the version of all the Derby jar files is (SVN revision 561794). Remember that derby.jar contains the embedded JDBC driver, while derbyclient.jar contains the client JDBC driver.

If derbyrun.jar is not available, you probably have an older version of derby. Then you must access sysinfo directly by doing for example:

cd /home/user/derby/lib/
java -cp derby.jar:derbytools.jar:derbyclient.jar:derbynet.jar

Refer to the documentation on Derby tools for more information about sysinfo.

Derby driver and server version (CLASSPATH)

Possible scenario: You don't know which version of Derby your application is using (that is, which version of Derby is in your CLASSPATH). For example, you have downloaded several products which bundle different versions of Derby and/or Java DB, and you are not quite sure which version your IDE is using.

Possible solution: Use the JDBC API (DatabaseMetaData).

Example: The following Java class demonstrates how to retrieve software version information using the database metadata.

   1 import java.sql.Connection;
   2 import java.sql.DatabaseMetaData;
   3 import java.sql.DriverManager;
   4 /**
   5  * Checks the version of the Derby software running a database.
   6  */
   7 public class DerbyVersionChecker {
   9     public static void main(String[] args) {
  10         try {
  11             // load the embedded driver
  12             Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
  13             // or the client driver...
  14             //Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
  16             // replace the following URL with your own, or use an existing connection:
  17             Connection conn = DriverManager.getConnection("jdbc:derby:testDB;create=true");
  19             // this will print the name and version of the software used for running this Derby system
  20             DatabaseMetaData dbmd = conn.getMetaData();
  21             String productName = dbmd.getDatabaseProductName();
  22             String productVersion = dbmd.getDatabaseProductVersion();
  23             System.out.println("Using " + productName + " " + productVersion);
  24         } catch (Exception ex) {
  25             ex.printStackTrace();
  26             System.exit(1);
  27         }
  28     }
  29 }

For example, if you are using Derby, and derby.jar is in your CLASSPATH, the above class will print:

Using Apache Derby - (561794)

Note: If you are using the client driver, the DatabaseMetaData#getDatabaseProductVersion() method returns the version of the software running the database, that is the version of the Derby Network Server (actually, the server is using the embedded driver to connect to the database). If you want to get the version of your JDBC driver (the Derby client driver) instead, use the DatabaseMetaData#getDriverVersion() method, as shown below. In an embedded scenario the embedded driver itself runs the database, so the two methods will return the same result.

String driverVersion = dbmd.getDriverVersion();

JDBC specification support

Possible scenario: You want to use some special feature that is not available in all versions of JDBC. You are not sure which JDBC version your Java VM supports, but want to find out.

Possible solution: Try to access classes/interfaces introduced in or removed from certain JDBC-related specifications.

Example: The following Java code demonstrates this in a way that is similar to how Derby's test harness determines the level of JDBC support in the current JVM:

   1     private void printJDBCSupportInVM() {
   3         /* Check the availability of classes or interfaces introduced in or
   4          * removed from specific versions of JDBC-related specifications. This
   5          * will give us an indication of which JDBC version this Java VM is
   6          * supporting.
   7          */
   8         if (haveClass("java.sql.SQLXML")) {
   9             System.out.println("JDBC 4");
  10         } else if (haveClass("java.sql.Savepoint")) {
  11             // indication of JDBC 3 or JSR-169.
  12             // JSR-169 is a subset of JDBC 3 which does not include the java.sql.Driver interface
  13             if (haveClass("java.sql.Driver")) {
  14                 System.out.println("JDBC 3");
  15             } else {
  16                 System.out.println("JSR-169");
  17             }
  18         } else if (haveClass("java.sql.Blob")) {
  19             // new in JDBC 2.0.
  20             // We already checked for JDBC 3.0, 4.0 and JSR-169, all of which also
  21             // include this class. Chances are good this is JDBC 2.x
  22             System.out.println("JDBC 2");
  23         } else if (haveClass("java.sql.Connection")) {
  24             // included in most (all?) JDBC specs
  25             System.out.println("Older than JDBC 2.0");
  26         } else {
  27             // JDBC support is missing (or is older than JDBC 1.0?)
  28             System.out.println("No valid JDBC support found");
  29         }
  30     }
  32    /**
  33     * Checks whether or not we can load a specific class.
  34     * @param className Name of class to attempt to load.
  35     * @return true if class can be loaded, false otherwise.
  36     */
  37    private static boolean haveClass(String className) {
  38        try {
  39            Class.forName(className);
  40            return true;
  41        } catch (Exception e) {
  42            return false;
  43        }
  44    }

For example, if you are running a Java SE 6 VM you will have JDBC 4 support, so the printJDBCSupportInVM() method prints:


Note that Derby JDBC drivers of version and later include support for JDBC 4.

VersionInfo (last edited 2009-09-20 22:11:22 by localhost)