why Derby

Introduction

This tutorial requires the Java Development Kit (JDK) and the Apache Derby software.

First, this section describes which JDK release is required, asks you to install it if you haven't already, then shows you how to configure and verify your installation.

Next, it shows you how to install the Apache Derby software, configure your environment to use the Derby Embedded JDBC driver, and verify your installation with the Derby sysinfo tool.

Java Development Kit (JDK)

Derby requires Java 2 Standard Edition (J2SE) 8 or higher. Only the Java Runtime Environment (JRE) is required to run Derby, but this tutorial compiles a Java application, so it requires the Java Development Kit (JDK).

If you already have a JDK installed, verify you are configured to use it, then proceed to the Apache Derby installation section.

Install JDK

If you have not already installed a JDK, download and install it now. No specific vendor implementation is required; the only requirement is that it be certified for J2SE 8 or higher. Java's reference implementation is athttp://www.oracle.com/technetwork/java/javase/downloads/index.html. After installing the JDK of your choice, proceed to the next section.

Configure JDK

Set the JAVA_HOME environment variable to the root location of the JDK installation directory. The examples below use C:\jdk1.8 for Windows and /opt/jdk1.8 for UNIX, but be sure to use the actual location on your system. (e.g. The default installation location used by the JDK installer might be something like C:\Program Files\Java\jdk1.8.0_11-b21)

Windows:C:\> set JAVA_HOME=C:\jdk1.8

UNIX Korn Shell:$ export JAVA_HOME=/opt/jdk1.8

Next set the PATH environment variable to include the JDK bin directory. The PATH variable tells the operating system where to find thejava interpreter and the javac compiler.

Windows:C:\> set PATH=%PATH%;%JAVA_HOME%\bin

In Windows, these environment variables can also be set from - right click "My Computer" -> Advanced -> Environment Variables.

UNIX Korn Shell:$ export PATH=$JAVA_HOME/bin:$PATH

Verify JDK

Use the java -version command, as shown below, to verify the installed release:

java -versionjava version "1.8.0_11"Java(TM) SE Runtime Environment (build 1.8.0_11-b21)Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

The output you see may be different from what is shown above because the java -version command outputs vendor-specific information; however, if you don't see what looks like valid version information, then STOP! And don't proceed until you resolve that problem.

Apache Derby

Download Derby

Download the binary Apache Derby distribution from the Derby web site at http://db.apache.org/derby/derby_downloads.html. These tutorial instructions use version 10.14.1.0 and assume you downloaded one of the binary distribution files listed in the table below:

Operating SystemDownload File
Windowsdb-derby-10.14.1.0-bin.zip
UNIX, Linux, and Macdb-derby-10.14.1.0-bin.tar.gz

If a more recent release is available, download that, then substitute that version number for 10.14.1.0 in the following instructions.

Install Derby

Choose the directory into which you want to install the Derby software. You must have write permissions to this directory. The sample instructions below use C:\Apache for Windows and /opt/Apache for UNIX; be sure to use your actual location. Copy the software distribution to the location you choose, then extract it as shown below.

Windows (use your extraction tool e.g. WinZip -- these instructions use mks unzip):mkdir C:\Apachecopy db-derby-10.14.1.0-bin.zip C:\Apachecd C:\Apacheunzip db-derby-10.14.1.0-bin.zip

UNIX:mkdir /opt/Apachecp db-derby-10.14.1.0-bin.tar.gz /opt/Apachecd /opt/Apachetar xzvf db-derby-10.14.1.0-bin.tar.gz

In both cases, the software will now be extracted into a subdirectory named db-derby-10.14.1.0-bin.

Set DERBY_INSTALL

Set the DERBY_INSTALL variable to the location where you installed Derby. Examples are shown below, but be sure to use the actual location on your system:

Windows:C:\> set DERBY_INSTALL=C:\Apache\db-derby-10.14.1.0-bin

UNIX Korn Shell:$ export DERBY_INSTALL=/opt/Apache/db-derby-10.14.1.0-bin

Configure Embedded Derby

To use Derby in its embedded mode set your CLASSPATH to include the jar files listed below:

  • derby.jar: contains the Derby engine and the Derby Embedded JDBC driver
  • derbytools.jar: optional, provides the ij tool that is used by a couple of sections in this tutorial

You can set your CLASSPATH explicitly with the command shown below:

Windows:C:\> set CLASSPATH=%DERBY_INSTALL%\lib\derby.jar;%DERBY_INSTALL%\lib\derbytools.jar;.

UNIX:$ export CLASSPATH=$DERBY_INSTALL/lib/derby.jar:$DERBY_INSTALL/lib/derbytools.jar:.

Notice that multiple entries in the class path are separated by a semicolon (;) on Windows and a colon (:) on UNIX.

The Derby software provides another way to set CLASSPATH, using shell scripts (UNIX) and batch files (Windows). This tutorial shows how to set CLASSPATH explicitly and also how to use the Derby scripts to set it.

Change directory now into the DERBY_INSTALL/bin directory. The setEmbeddedCP.bat (Windows) and setEmbeddedCP (UNIX) scripts use the DERBY_INSTALL variable to set the CLASSPATH for Derby embedded usage. You can edit the script itself to set DERBY_INSTALL, or you can let the script get DERBY_INSTALL from your environment. Since you already set DERBY_INSTALL in the "Set DERBY_INSTALL" section above, you don't need to edit the script, so go ahead and execute it as shown below:

Windows:C:\> cd %DERBY_INSTALL%\binC:\Apache\db-derby-10.14.1.0-bin\bin> setEmbeddedCP.bat

UNIX:$ cd $DERBY_INSTALL/bin$ . setEmbeddedCP

Verify Derby

Run the sysinfo command, as shown below, to output Derby system information:

java org.apache.derby.tools.sysinfo

Successful output will look something like this:

------------------ Java Information ------------------Java Version: 1.8.0Java Vendor: Oracle CorporationJava home: /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jreJava classpath: /Users/me/src:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derby.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derby.war:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_cs.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_de_DE.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_es.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_fr.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_hu.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_it.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_ja_JP.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_ko_KR.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_pl.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_pt_BR.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_ru.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_zh_CN.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyLocale_zh_TW.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyclient.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbynet.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyoptionaltools.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyrun.jar:/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbytools.jar:/Users/me/sw/db2jcc/lib/db2jcc.jar:/Users/me/sw/db2jcc/lib/db2jcc_license_c.jar:/Users/me/sw/mysql/connectorj/mysql-connector-java-5.0.7/mysql-connector-java-5.0.7-bin.jar:/Users/me/sw/demo/jdbc.concurrent/jars/jdbc-concurrent.jar:/Users/me/sw/demo/tableFunctionWhitePaper/jars/vtis-example.jarOS name: Mac OS XOS architecture: x86_64OS version: 10.11.5Java user name: meJava user home: /Users/meJava user dir: /Users/me/derby/branches/10.14java.specification.name: Java Platform API Specificationjava.specification.version: 1.8java.runtime.version: 1.8.0-b132--------- Derby Information --------[/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derby.jar] 10.14.1.0 - (1808820)[/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbytools.jar] 10.14.1.0 - (1808820)[/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbynet.jar] 10.14.1.0 - (1808820)[/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyclient.jar] 10.14.1.0 - (1808820)[/Users/me/sw/z/db-derby-10.14.1.0-bin/lib/derbyoptionaltools.jar] 10.14.1.0 - (1808820)----------------------------------------------------------------------- Locale Information -----------------Current Locale : [English/United States [en_US]]Found support for locale: [cs] version: 10.14.1.0 - (1808820)Found support for locale: [de_DE] version: 10.14.1.0 - (1808820)Found support for locale: [es] version: 10.14.1.0 - (1808820)Found support for locale: [fr] version: 10.14.1.0 - (1808820)Found support for locale: [hu] version: 10.14.1.0 - (1808820)Found support for locale: [it] version: 10.14.1.0 - (1808820)Found support for locale: [ja_JP] version: 10.14.1.0 - (1808820)Found support for locale: [ko_KR] version: 10.14.1.0 - (1808820)Found support for locale: [pl] version: 10.14.1.0 - (1808820)Found support for locale: [pt_BR] version: 10.14.1.0 - (1808820)Found support for locale: [ru] version: 10.14.1.0 - (1808820)Found support for locale: [zh_CN] version: 10.14.1.0 - (1808820)Found support for locale: [zh_TW] version: 10.14.1.0 - (1808820)------------------------------------------------------

The output on your system will probably be somewhat different from the output shown above, but it should reflect the correct location of jar files on your machine and there shouldn't be any errors. If you see an error like the one below, it means your class path is not correctly set:

$ java org.apache.derby.tools.sysinfoException in thread "main" java.lang.NoClassDefFoundError: org/apache/derby/tools/sysinfo

Echo your CLASSPATH, as shown below, then double check each entry in your class path to verify that the jar file is where you expect it:

Windows:C:\> echo %CLASSPATH% C:\Apache\DB-DER~1.1-B\lib\derby.jar;C:\Apache\DB-DER~1.1-B\lib\derbytools.jar;

UNIX:$ echo $CLASSPATH/opt/Apache/db-derby-10.14.1.0-bin/lib/derby.jar:/opt/Apache/db-derby-10.14.1.0-bin/lib/derbytools.jar:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值