db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Db-derby Wiki] Update of "VersionInfo" by JohnHEmbretsen
Date Tue, 04 Sep 2007 12:44:59 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Db-derby Wiki" for change notification.

The following page has been changed by JohnHEmbretsen:

New page:
= Derby and JDBC version How-To =

''"Help! Which Derby version am I using?"''

'''Table of Contents'''

== 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).

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 org.apache.derby.tools.sysinfo
Refer to the [http://db.apache.org/derby/manuals/index.html documentation] on Derby tools
for more information about ''sysinfo''.

== Derby / database 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 [http://developers.sun.com/javadb/
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 version information using
the database metadata.
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
 * Checks the version of the derby driver currently loaded.
public class DerbyVersionChecker {
    public static void main(String[] args) {
        try {
            // load the embedded driver
            // or the client driver...
            // replace the following URL with your own, or use an existing connection:
            Connection conn = DriverManager.getConnection("jdbc:derby:testDB;create=true");
            // this will print the name and version of the JDBC driver used for this connection
            DatabaseMetaData dbmd = conn.getMetaData();
            String productName = dbmd.getDatabaseProductName();
            String productVersion = dbmd.getDatabaseProductVersion();
            System.out.println("Using " + productName + " " + productVersion);
        } catch (Exception ex) {
For example, if you are using Derby, and ''derby.jar'' is in your {{{CLASSPATH}}},
the above class will print:
Using Apache Derby - (561794)

== JDBC version ==

'''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

'''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:
    private void printJDBCSupportInVM() {

        /* Check the availability of classes or interfaces introduced in or
         * removed from specific versions of JDBC-related specifications. This
         * will give us an indication of which JDBC version this Java VM is
         * supporting.
        if (haveClass("java.sql.SQLXML")) {
            System.out.println("JDBC 4");
        } else if (haveClass("java.sql.Savepoint")) {
            // indication of JDBC 3 or JSR-169.
            // JSR-169 is a subset of JDBC 3 which does not include the java.sql.Driver interface
            if (haveClass("java.sql.Driver")) {
                System.out.println("JDBC 3");
            } else {
        } else {
            System.out.println("JDBC 2");
    * Checks whether or not we can load a specific class, and uses this to 
    * determine JDBC level.
    * @param className Name of class to attempt to load.
    * @return true if class can be loaded, false otherwise.
   private static boolean haveClass(String className) {
       try {
           return true;
       } catch (Exception e) {
           return false;
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 (binary) support for JDBC

View raw message