Chapter 21. JDBC インタフェース

Table of Contents
JDBC インタフェースの構築
JDBC のためのデータベースの準備
ドライバの使用
JDBC の インポート
ドライバの読み込み
データベースへの接続
問い合わせの発行、及び、結果の処理
更新処理
接続を閉じる
ラージオブジェクトの使用
PostgresJDBC API への拡張
今後に読むべきもの

著者: Written by Peter T. Mount, the author of the JDBC driver.

JDBC ドライバの作者である、 Peter T. Mount 氏によって記述 されました。

JDBC is a core API of Java 1.1 and later. It provides a standard set of interfaces to SQL-compliant databases.

JDBC は Java 1.1 以降のコア API です。SQL 互換のデータベー スへのインタフェースの標準セットを提供します。

Postgres provides a type 4 JDBC Driver. Type 4 indicates that the driver is written in Pure Java, and communicates in the database's own network protocol. Because of this, the driver is platform independent. Once compiled, the driver can be used on any platform.

Postgres は、タイプ 4 の JDBC ドライバを提供します。タイプ 4 とは、その ドライバが Pure Java で作成され、データベース独自のネットワークプ ロトコルで通信を行なうことを意味します。このため、そのドライバはプ ラットホームに依存しません。一度コンパイルを行なえば、そのドライバ はどのプラットホームでも使用することができます。

JDBC インタフェースの構築

ドライバのコンパイル

The driver's source is located in the src/interfaces/jdbc directory of the source tree. To compile simply change directory to that directory, and type:

ドライバのソースは、ソースツリーの src/interfaces/jdbc ディレクトリにあります。 コンパイルするには、単にこのディレクトリに移動して、以下を入力し ます。

% make

Upon completion, you will find the archive postgresql.jar in the current directory. This is the JDBC driver.

完了すると、カレントディレクトリに postgresql.jar アーカイブができます。これが JDBC ドライバです。

Note: You must use make, not javac, as the driver uses some dynamic loading techniques for performance reasons, and javac cannot cope. The Makefile will generate the jar archive.

必ず javac ではなく、 make を使用して下さい。ドライバは性能向上 を目的とした、動的読み込み技術をいくつか使用していますが、 javac ではこれをうまく処理できないからです。 Makefile は jar アーカイブを作成します。

ドライバのインストール

To use the driver, the jar archive postgresql.jar needs to be included in the CLASSPATH.

ドライバを使用するためには、この jar アーカイブを CLASSPATH に含め る必要があります。

Example:

I have an application that uses the JDBC driver to access a large database containing astronomical objects. I have the application and the jdbc driver installed in the /usr/local/lib directory, and the java jdk installed in /usr/local/jdk1.1.6.

天文学に関するオブジェクトをもつ巨大なデータベースにアクセスする ために JDBC ドライバを使用するアプリケーション があります。このアプリケーションと jdbc ドライバを /usr/local/lib ディレクトリにインストールしました。また、Java JDK は /usr/local/jdk1.1.6 にインストールされています。

To run the application, I would use:

このアプリケーションを実行する場合

export CLASSPATH = \ /usr/local/lib/finder.jar:/usr/local/lib/postgresql.jar:. java uk.org.retep.finder.Main

とします。

Loading the driver is covered later on in this chapter.

ドライバの読み込みについては、この章の後で示します。