Quick Startfor Web Application
ユーザ管理webアプリケーション用データベースを作成します。
- ユーザが入力する箇所を太字で記載しています。
- <path to PostgreSQL bin directory> はPostgreSQLのbinディレクトリのパスに置き換えてください。
例) c:\Program Filse\PostgreSQL\8.1\bin - <Postgres user password> はPostgresユーザのパスワードに読み替えてください。
コマンドプロンプトで以下のコマンドを実行します。
$ cd <path to postgreSQL bin directory> $ createuser -d -P -U postgres -W falcon Enter password for new role: falcon ←入力された文字は表示されません Enter it again: falcon ←入力された文字は表示されません Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create more new roles? (y/n) n Password: <postgres user password> ←入力された文字は表示されません CREATE ROLE
コマンドプロンプトで以下のコマンドを実行します。
$ cd <path to postgreSQL bin directory> $ createdb -U falcon falcon Password: falcon ←入力された文字は表示されません CREATE DATABASE
コマンドプロンプトで以下のコマンドを実行します。
$ cd <path to postgreSQL bin directory> $ psql -U falcon Password for user falcon: falcon ←入力された文字は表示されません Welcome to psql 8.1.3, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit falcon=> \l List of databases Name | Owner | Encoding -----------+----------+---------- falcon | falcon | EUC_JP ←falconデータベースが作成されていることを確認します postgres | postgres | EUC_JP template0 | postgres | EUC_JP template1 | postgres | EUC_JP (4 rows) falcon=> \q
ユーザ情報を保持するテーブル(m_user)の定義と作成を行います。
- Eclipseでfalcon-web-tutorial/WEB-INF/falcon/db.xmlファイル(以下db.xmlファイル)を開き、リスト 2-2のように修正を行います。
<?xml version="1.0" encoding="Windows-31J"?> <db:db xmlns:f="http://www.scw.co.jp/falcon" xmlns:db="http://www.scw.co.jp/falcon/db" name="falcon" connection="falcon"> <db:connection name="falcon" driver="org.postgresql.Driver" uri="jdbc:postgresql:falcon" user="falcon" password="falcon"/> <db:table name="m_user" desc="ユーザマスタ"> <db:column name="ID" desc="ID" size="36" type="CHAR" notNull="true" primaryKey="true"/> <db:column name="VERSION" desc="VERSION番号" size="10" type="INT" notNull="true"/> <db:column name="user_id" desc="ユーザID" size="128" type="VARCHAR" notNull="true"/> <db:column name="password" desc="ログインパスワード" size="128" type="VARCHAR" notNull="true"/> <db:column name="user_name" desc="名前" size="128" type="VARCHAR" notNull="false"/> <db:column name="mail" desc="メールアドレス" size="128" type="VARCHAR" notNull="false"/> <db:column name="zip" desc="郵便番号" size="7" type="VARCHAR" notNull="false"/> <db:column name="address" desc="住所" size="256" type="VARCHAR" notNull="false"/> <db:column name="tel" desc="電話番号" size="11" type="VARCHAR" notNull="false"/> <db:column name="birthday" desc="誕生日" size="8" type="VARCHAR" notNull="false"/> <db:index name="user_id" desc="ユーザIDのユニークインデックス" column="user_id" unique="true"/> </db:table> </db:db>
リスト 2-2 db.xmlファイル
- Eclipseでfalcon-web-tutorial/WEB-INF/falcon/deploy.xmlファイル(以下deploy.xmlファイル)を開き、以下の修正を行います。
<?xml version="1.0" encoding="Windows-31J"?> <f:falcon xmlns:f="http://www.scw.co.jp/falcon" xmlns:st="http://www.scw.co.jp/falcon/statement" xmlns:dao="http://www.scw.co.jp/falcon/dao"> <dao:createTable table="m_user"/> <!-- ←作成するテーブルを指定します --> </f:falcon>
リスト 2-3 deploy.xmlファイル
- ブラウザで以下のURLにアクセスし、db.xml、deoloy.xmlファイルの修正内容を反映します。
http://localhost:8080/tutorial/?control=init
- ブラウザで以下のURLにアクセスし、m_userテーブルを作成します。
http://localhost:8080/tutorial/?control=deploy
- テーブルの確認
コマンドプロンプトで、以下のコマンドを実行します。$ cd <path to postgreSQL bin directory> $ psql -U falcon -d falcon Password for user falcon: falcon ←入力された文字は表示されません Welcome to psql 8.1.3, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit falcon=> \dt List of relations Schema | Name | Type | Owner --------+--------+-------+-------- public | m_user | table | falcon ←m_userテーブルが作成されていることを確認します (1 row) falcon=> \q
2.2.4で作成したテーブルをfalconで参照できるようにレコードとオブジェクトのマッピングを行います。
- Eclipseでdb.xmlファイルを開き、以下のように修正を行います。
<?xml version="1.0" encoding="Windows-31J"?> <db:db xmlns:f="http://www.scw.co.jp/falcon" xmlns:db="http://www.scw.co.jp/falcon/db" name="falcon" connection="falcon"> <db:connection name="falcon" driver="org.postgresql.Driver" uri="jdbc:postgresql:falcon" user="falcon" password="falcon"/> <db:table name="m_user" desc="ユーザマスタ"> <db:column name="ID" desc="ID" size="36" type="CHAR" notNull="true" primaryKey="true"/> <db:column name="VERSION" desc="VERSION番号" size="10" type="INT" notNull="true"/> <db:column name="user_id" desc="ユーザID" size="128" type="VARCHAR" notNull="true"/> <db:column name="password" desc="ログインパスワード" size="128" type="VARCHAR" notNull="true"/> <db:column name="user_name" desc="名前" size="128" type="VARCHAR" notNull="false"/> <db:column name="mail" desc="メールアドレス" size="128" type="VARCHAR" notNull="false"/> <db:column name="zip" desc="郵便番号" size="7" type="VARCHAR" notNull="false"/> <db:column name="address" desc="住所" size="256" type="VARCHAR" notNull="false"/> <db:column name="tel" desc="電話番号" size="11" type="VARCHAR" notNull="false"/> <db:column name="birthday" desc="誕生日" size="8" type="VARCHAR" notNull="false"/> <db:index name="user_id" desc="ユーザIDのユニークインデックス" column="user_id" unique="true"/> </db:table> <!-- ↓カラムとフィールド名の関連を定義します。--> <db:mapping name="userMap" table="m_user" key="ID" version="VERSION"> <db:field column="user_id" as="user_id"/> <db:field column="password" as="password"/> <db:field column="user_name" as="user_name"/> <db:field column="mail" as="mail"/> <db:field column="zip" as="zip"/> <db:field column="address" as="address"/> <db:field column="tel" as="tel"/> <db:field column="birthday" as="birthday"/> </db:mapping> </db:db>
リスト 2 4 db.xmlファイル