SAK 図書館
PostgreSQL + Web 編2 - JAVA Servlet、JSP、J2SDK、Tomcat、JDBC 環境
■PostgreSQL + JDBC、JAVA Servlet、JSP 環境
・PostgreSQL を JAVA サーブレット、JSP でアクセスするための環境を準備
する。これまた win32 版がなかなかわからず、Tomcat で試してみる。
Apache と Tomcat の連携については、次の資料を参考にして下さい。
PostgreSQL + Web 編3 - Apache、Tomcat 連携、mod_jk.dll、mod_jk.conf
■JAVA2 SDK 1.3.1 インストール
・PostgreSQL 7.0.2 なら、J2SDK として、j2sdk-1_3_1-win.exe を
c:/cygnus/j2sdk/ としてインストールする。
■JAVA2 SDK 1.4.0 インストール
・PostgreSQL 7.2.3 なら、J2SDK として、j2sdk-1_4_0-win.exe を
c:/cygnus/j2sdk/ としてインストールする。
■Tomcat 3.3.1 インストール
・Tomcat は、JAVA Servlet 2.2、JAVA Server Page 1.1 に簡易ウェブサーバ
がセットになっている。
jakarta-tomcat-3.3.1.zip を解凍して、jakarta-tomcat-3.3.1 フォルダを
c:/cygnus/jakarta-tomcat-3.3.1/ として配置する。
■.bashrc に Tomcat 設定追加
・Tomcat 環境変数 TOMCAT_HOME、JAVA_HOME を .bashrc に追加する。
尚、修正後に「source /.bashrc」と実行するか、Cygwin B20 を再起動する
必要がある。
export HOME=/
export PATH=/j2sdk/bin:/usr/local/mysql/bin:/usr/local/perl/bin:$PATH:/usr/local/pgsql/bin:/usr/local/bin:/usr/local/apache
export POSTGRES_HOME=/usr/local/pgsql
export PGLIB=/usr/local/pgsql/lib
export PGDATA=/usr/local/pgsql/data
export LD_LIBRARY_PATH=/usr/local/pgsql/lib:/usr/local/lib
export TOMCAT_HOME=c:/cygnus/jakarta-tomcat-3.3.1
export JAVA_HOME=/j2sdk
export CLASSPATH=c:/cygnus/jakarta-tomcat-3.3.1/lib/common/servlet.jar
cd
ls -aF
■mount 設定
・JAVA ソース用に g:/tmp/ を「mount -f g:/tmp /src」としてマウントする。
mount -f g:/tmp /src
Device Directory Type Flags
c:\cygnus\cygwin-b20\share /sw/cygwin-b20/share native text!=binary
g:\tmp /src native text!=binary
c:\cygnus / native text!=binary
■Tomcat 起動、終了
・Tomcat の起動は、次のようにする。
cd /jakarta-tomcat-3.3.1/bin
startup.sh
・Tomcat の終了は、次のようにする。
cd /jakarta-tomcat-3.3.1/bin
shutdown.sh
■Tomcat ウェブサーバアクセス
・Tomcat ウェブサーバ root へは、次のようにアクセスする。
http://sak-design:8080/
・Apache ウェブサーバ www へは、次のようにアクセスする。
Apache サービスを起動しておけば、両方の環境が同時に使用できた。
http://sak-design/
・尚、Apache に統合できないかと挑戦したが、エラーに悩まされて今回は
見送った。
■PostgreSQL JDBC ドライバコンパイル
・JAVA Servlet、JSP で PostgreSQL にアクセスするための JDBC ドライバ
postgresql.jar をコンパイル作成する。
export CLASSPATH=./
cd /usr/src/pgsql/postgresql-7.0.2/src/interfaces/jdbc
make jdbc2
・次のように make が終了すれば、
/usr/src/pgsql/postgresql-7.0.2/src/interfaces/jdbc/ に
正しく postgresql.jar ができている。
...
...
...
------------------------------------------------------------
The JDBC driver has now been built. To make it available to
other applications, copy the postgresql.jar file to a public
place (under unix this could be /usr/local/lib) and add it
to the class path.
Then either add -Djdbc.drivers=org.postgresql.Driver to the
commandline when running your application, or edit the
properties file for your application (~/.hotjava/properties
under unix for HotJava), and add a line containing
jdbc.drivers=org.postgresql.Driver
More details are in the README file and in the main postgresql
documentation.
------------------------------------------------------------
To build the examples, type:
JDBC1: make examples
JDBC2: make examples2
To build the CORBA example (requires Java2):
make corba
To make the tests, type:
make tests
------------------------------------------------------------
・JDBC 接続テスト用サンプルコードをコンパイルする。
export CLASSPATH=./
cd /usr/src/pgsql/postgresql-7.0.2/src/interfaces/jdbc
make examples2
・JDBC 接続テストをする。
ipc-daemon &
postmaster -i &
export CLASSPATH=./
cd /usr/src/pgsql/postgresql-7.0.2/src/interfaces/jdbc
java example.basic jdbc:postgresql:template1 SAK SAK
export CLASSPATH=c:/cygnus/jakarta-tomcat-3.3.1/lib/common/servlet.jar
・正常な example.basic の処理結果は次のとおり。
PostgreSQL basic test v6.3 rev 1
Connecting to Database URL = jdbc:postgresql:template1
Connected...Now creating a statement
ERROR: Relation 'basic' does not exist
Running tests:
Updated 3 rows
performing a query
a=1 b=8
a=2 b=8
a=3 b=8
a=4 b=2
a=4 b=3
a=4 b=4
performing another query
a=1 b=8
a=2 b=8
a=3 b=8
a=4 b=2
a=4 b=3
a=4 b=4
Now closing the connection
■JDBC ドライバ postgresql.jar インストール
・PostgreSQL 7.0.2 の JDBC ドライバは、次のようにインストールする。
c:/cygnus/jakarta-tomcat-3.3.1/webapps/sak/WEB-INF/lib/postgresql.jar
・webapps/sak/WEB-INF/lib/ の作成については、次の資料を参考にして下さい。
PostgreSQL + Servlet、JSP 編1 - war 作成、JDBC 配置、Servlet, JSP テスト
・CLASSPATH は、次のようにした。
尚、Cygwin B20 では、「"」で囲まないと「;」でエラーになる。
また、普通のパスは、Cygwin B20 では「:」で区切るが、CLASSPATH は、
DOS と同じく「;」でかつ、「c:/...」のようにシステムパスから指定する
必要がある。
export CLASSPATH=".;c:/cygnus/jakarta-tomcat-3.3.1/lib/common/servlet.jar;c:/cygnus/jakarta-tomcat-3.3.1/webapps/sak/WEB-INF/lib/postgresql.jar"
■JDBC ドライバ pgjdbc2.jar インストール
・PostgreSQL 7.2.3 の JDBC ドライバは、次のようにインストールする。
pgjdbc2.jar については、JDBC ドライバの make もうまくいかず、ダウン
ロードしてきた。(Servlet や JSP のソースの修正は不要であった。)
c:/cygnus/jakarta-tomcat-3.3.1/webapps/sak/WEB-INF/lib/pgjdbc2.jar
・webapps/sak/WEB-INF/lib/ の作成については、次の資料を参考にして下さい。
PostgreSQL + Servlet、JSP 編1 - war 作成、JDBC 配置、Servlet, JSP テスト
・CLASSPATH は、次のようにした。
尚、Cygwin B20 では、「"」で囲まないと「;」でエラーになる。
また、普通のパスは、Cygwin B20 では「:」で区切るが、CLASSPATH は、
DOS と同じく「;」でかつ、「c:/...」のようにシステムパスから指定する
必要がある。
export CLASSPATH=".;c:/cygnus/jakarta-tomcat-3.3.1/lib/common/servlet.jar;c:/cygnus/jakarta-tomcat-3.3.1/webapps/sak/WEB-INF/lib/pgjdbc2.jar"
■PostgreSQL 編、JAVA Servlet、JSP 編資料
■MySQL 編資料
■SQL 基礎編資料
■SQL 基礎実地編資料
■SQL チューニング編資料
■Oracle PL/SQL 編資料