我的控制台 会员登陆 免费注册 最后更新 高级搜索 返回首页 我要投稿 退出登陆 开源电脑书库 开源学习笔记 极点软件园 中华励志网 开源技术研究
当前在线: 27
开源资讯
开源文化
初级入门
系统管理
网络管理
网络安全
服务器应用
Linux认证教学
开源开发技术
开源操作系统开发
开源企业级解决方案
理论研究
开源文摘 / 开源开发技术 / JAVA语言开发 / Apache Derby Tutorial:Derby DB快速入门
Apache Derby Tutorial:Derby DB快速入门
2007-08-03       开源文摘    点击: 9267
Apache Derby Tutorial:Derby DB快速入门         

Apache Derby, an Apache DB subproject, is a relational database implemented in Java. Its footprint is so small you can easily embed it in any Java-based solution. In addition to its embedded framework, Derby supports a more familiar client/server framework with the Derby Network Server. This tutorial introduces Derby's basic features and walks you through using both frameworks; first the embedded framework using the Derby Embedded JDBC driver, then the Network Server framework using the Derby Network Client JDBC driver.

第一步:安装软件 Step 1: Install Software

  • Introduction
  • Java Development Kit (JDK)
    • Install JDK
    • Configure JDK
    • Verify JDK
  • Apache Derby
    • Download Derby
    • Install Derby
    • Set DERBY_INSTALL
    • Configure Embedded Derby
    • Verify 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) 1.3 or higher (this tutorial was developed using JDK 1.4.2). 如果运行Derby的话只需要JRE即可,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 1.3 or higher. Java's reference implementation is at http://java.sun.com/j2se/. 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.4 for Windows and /opt/jdk1.4 for UNIX, but be sure to use the actual location on your system.

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

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

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

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

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 -version java version "1.4.2_04" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) Java HotSpot(TM) Client VM (build 1.4.2_04-b05, 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.1.2.1 and assume you downloaded one of the binary distribution files listed in the table below:

Operating System Download File
Windows db-derby-10.1.2.1-bin.zip
UNIX, Linux, and Mac db-derby-10.1.2.1-bin.tar.gz

If a more recent release is available, download that, then substitute that version number for 10.1.2.1 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 -- these instructions show mks unzip): mkdir C:\Apache copy db-derby-10.1.2.1-bin.zip C:\Apache cd C:\Apache unzip db-derby-10.1.2.1-bin.zip

UNIX: mkdir /opt/Apache cp db-derby-10.1.2.1-bin.tar.gz /opt/Apache cd /opt/Apache tar xzvf db-derby-10.1.2.1-bin.tar.gz

In both cases, the software will now be extracted into a subdirectory named db-derby-10.1.2.1-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.1.2.1-bin

UNIX Korn Shell: $ export DERBY_INSTALL=/opt/Apache/db-derby-10.1.2.1-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 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/frameworks/embedded/bin directory. The setEmbeddedCP.bat (Windows) and setEmbeddedCP.ksh (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%\frameworks\embedded\bin C:\Apache\db-derby-10.1.2.1-bin\frameworks\embedded\bin> setEmbeddedCP.bat

UNIX: $ cd $DERBY_INSTALL/frameworks/embedded/bin $ . setEmbeddedCP.ksh

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.4.2_06
Java Vendor: Sun Microsystems Inc.
Java home: /opt/jdk1.4
Java classpath: /opt/Apache/db-derby-10.1.2.1-bin/lib/derby.jar:/opt/Apache/db-derby-10.1.2.1-bin/lib/derbytools.jar:
OS name: Linux
OS architecture: i386
OS version: 2.6.10-1.760_FC3
Java user name: jta
Java user home: /home/jta
Java user dir: /opt/Apache/db-derby-10.1.2.1-bin/frameworks/embedded/bin java.specification.name:
Java Platform API Specification java.specification.version: 1.4
--------- Derby Information --------
JRE - JDBC: J2SE 1.4.2 - JDBC 3.0
[/opt/Apache/db-derby-10.1.2.1-bin/lib/derby.jar] 10.1.2.1 - (330608)
[/opt/Apache/db-derby-10.1.2.1-bin/lib/derbytools.jar] 10.1.2.1 - (330608)
------------------------------------------------------
 -----------------Locale Information -----------------
------------------------------------------------------

The output on your system will probably be somewhat different than 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.sysinfo Exception 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.1.2.1-bin/lib/derby.jar:/opt/Apache/db-derby-10.1.2.1-bin/lib/derbytools.jar:

If sysinfo outputs valid information, you're ready to move to "Step 2: ij Basics".

责任编辑: mayu8758
Step 2: ij Basics »
发表评论 查看评论 加入收藏 Email给朋友 打印本文
如果你想对该文章评分, 请先登陆, 如果你仍未注册,请点击注册链接注册成为本站会员.
平均得分 0, 共 0 人评分
1 2 3 4 5 6 7 8 9 10
 
开源文摘(Open Source Digest):最新 高质量 原创 转载 文章100%经站长亲自验证!
Opendigest
is powered by Open Source Technology : Linux Apache PHP MySQL
"开源文摘"豫ICP备06013383号
OASA - OASA CR
关闭