Apache Derby -上手2

下面我们直接进入Apache Derby 指导手册,学习如何安装使用Derby

Tutorial Topics

This tutorial is organized into the sections below:

  1. Install Software shows how to:
    • Install the Apache Derby software.
    • Configure your environment to use the Derby Embedded JDBC driver.
    • Verify your installation with the sysinfo tool.
  2. ij Basics shows how to use the ij tool with the embedded Derby JDBC driver to create a database and execute SQL queries.
  3. Embedded Derby shows how to compile and run a simple Java application that uses the Derby Embedded JDBC driver.
  4. Derby Network Server show how to:
    • Start the Derby Network Server.
    • Configure your environment to use the Derby Network Client JDBC driver.
    • Compile and run a simple Java application that uses the network server.
==================================翻译=========================================
| Install Software 主要描述了如何:
  -安装apahce derby 软件
  -配置你的环境来使用Derby嵌入的JDBC驱动
  -使用系统信息工具验证你的安装
| ij Basics  描述了如果通过嵌入的Derby JDBC驱动使用ij 工具去创建数据库和执行Sql查询
| Embedded Derby  描述了如何编译和运行一个使用Derby嵌入的jdbc驱动的java应用程序
| Derby Network Server 描述了如何使用:
 -启动Derby网络服务
 -配置环境以使用Derby网络客户端JDBC驱动
 -配置和运行一个简单的使用了网络服务的java 应用程序

[html]  view plain copy
  1.   

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 sysinfotool.

==================================翻译=========================================

环境需要JDK以及APache derby 软件

首先,这个部分描述了需要什么版本的JDK,如果你还没有安装,请安装。然后教你如何配置和验证你的安装。

然后,描述如果安装Apache Derby 软件,配置你的环境来使用Derby嵌入的JDBC驱动,和使用Derby sysinfotool来验证你的安装

Java Development Kit (JDK)

Derby requires Java 2 Standard Edition (J2SE) 1.4.2 or higher (this tutorial was developed using JDK 1.5). 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.

==================================翻译=========================================

Derby 要求 J2SE1.42或者更高的版本(本次示例环境使用了JDK1.5)。运行Derby只要求JRE,但是如果编译一个java应用程序,需要JDK

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.4.2 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.

==================================翻译=========================================

如果你还没安装JDK,现在下载并且安装。没有要求指定的提供商实现,唯一的要求就是要确认J2Se的版本是1.42或者更高的版本。

Configure JDK

Set the JAVA_HOME environment variable to the root location of the JDK installation directory. The examples below use C:\jdk1.5 for Windows and /opt/jdk1.5 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.5.0_06)

==================================翻译=========================================

配置JDK,设置JDK的安装根目录到JAVA_HOME环境变量中。下面示例windows下使用 C:\jdk1.5 UNIX下使用/opt/jdk1.5。要确认在你的系统中的实际目录。

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

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

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.

==================================翻译=========================================

设值jdk下的bin目录到PATH环境变量中。

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

In Windows, these envoronment 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 -version命令来验证安装版本信息:

java -versionjava version "1.5.0_06"Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

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.8.1.2 and assume you downloaded one of the binary distribution files listed in the table below:

==================================翻译=========================================

从Derby网站:http://db.apache.org/derby/derby_downloads.html下载Derby发行版。本指导手册的介绍使用的版本为10.8.1.2,假设你已经下载了一个下表中所列的发行版文件:

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

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

==================================翻译=========================================

请下载最新的可用发行版,替换下面文章中所使用的10.8.1.2的版本。

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.8.1.2-bin.zip C:\Apachecd C:\Apacheunzip db-derby-10.8.1.2-bin.zip

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

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

==================================翻译=========================================

选择你想要Derby安装的目录。你必须拥有对该目录写的权限。本示例windows下使用C:\Apache,Unix下使用/opt/Apache。请确认时间路径。拷贝软件发行版本到你选择的路径下。然后按如下方式解压。

--这边我就不翻译了。

两个情景,软件都会被解压到一个名叫db-derby-10.8.1.2-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:

==================================翻译=========================================

将你安装Derby目录路径设置到DERBY_INSTALL变量中。示例如下,需要确认你系统中的实际路径。

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

UNIX Korn Shell:$ export DERBY_INSTALL=/opt/Apache/db-derby-10.8.1.2-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:

==================================翻译=========================================

要使用Derby的嵌入模式,设置你的CLASSPATH 包含如下的jar文件

| derby.jar:包含Derby引擎和Dery嵌入式JDBC驱动

| derbytools.jar:可选的,提供ij工具,这个工具在下面的一些章节中使用到。

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.ksh (UNIX) scripts use the DERBY_INSTALL variable to set theCLASSPATH 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:

==================================翻译=========================================

注意在class path中的多个输入要用符号分割开,window下位(;),UNIX下位(:)

Derby提供了另外一个方式来设置CLASSPATH,UNIX使用shell脚本,Windows下使用批处理,本手册展示了如果直接设置CLASSPATH和如何使用Derby脚本设置。

打开DERBY_INSTALL/bin目录,setEmbeddedCP.bat(windows下)或setEmbeddedCP.ksh (UNIX下)两个脚本通过使用DERBY_INSTALL 变量来设置运行Derby嵌入式功能所需要设置的CLASSPATH 。你可以编辑这个脚本来设置DERBY_INSTALL,或则你可以让脚本从你环境中获取DERBY_INSTALL。如果你已经在 "Set DERBY_INSTALL" 部分设置了DERBY_INSTALL ,你不需要再编辑脚本,直接像下面这样运行它。

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

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

Verify Derby

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

==================================翻译=========================================

像下面这样运行系统命令,将会输出Derby系统系。

java org.apache.derby.tools.sysinfo

Successful output will look something like this:

==================================翻译=========================================

成功的输出像下面这样。

------------------ Java Information ------------------Java Version: 1.5.0_06Java Vendor: Sun Microsystems Inc.Java home: C:\jdk1.5Java classpath: C:\Apache\DB-DER~1.1-B\lib\derby.jar;C:\Apache\DB-DER~1.1-B\lib\derbytools.jar;OS name: Windows XPOS architecture: x86OS version: 5.1Java user name: userJava user home: C:\Documents and Settings\userJava user dir: C:\Apache\db-derby-10.8.1.2-bin\binjava.specification.name: Java Platform API Specificationjava.specification.version: 1.5--------- Derby Information --------JRE - JDBC: J2SE 5.0 - JDBC 3.0[C:\Apache\db-derby-10.8.1.2-bin\lib\derby.jar] 10.8.1.2 - (1095077)[C:\Apache\db-derby-10.8.1.2-bin\lib\derbytools.jar] 10.8.1.2 - (1095077)----------------------------------------------------------------------- Locale Information -----------------Current Locale : [English/United States [en_US]]Found support for locale: [cs]...Found support for locale: [zh_TW] version: 10.8.1.2 - (1095077)------------------------------------------------------

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:

==================================翻译=========================================

你系统上的输入业务会和上面的输出有些不同,如果你映射到你机器上正确的jar文件的目录,就不会出现错误。如果你看到如下的错误,就代表你class path没有正确设置。

$ 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:

==================================翻译=========================================

打印你的CLASSPATH,和下面一样,然后再次检查你所期望的jar文件的路径在class path中是否正确。

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.8.1.2-bin/lib/derby.jar:/opt/Apache/db-derby-10.8.1.2-bin/lib/derbytools.jar:

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

==================================翻译=========================================

如果系统信息输出了正确的信息。你可以到下个章节:"Step 2: ij Basics".
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值