I haven't included any detail on installing Tomcat, the binary makes it
very easy.
Installing Postgresql needs more explanation than I have space for so check
the documentation that came with your postgresql version.
You must do this as a postgresql user already recognised by the database and with permissions to create other users.
[arkwright:~] createuser Enter name of user to add: jspuser Shall the new user be allowed to create databases? (y/n) y Shall the new user be allowed to create more new users? (y/n) y CREATE USERThe permissions given to this user are irrelevant for our purposes.
[arkwright:~] createdb -U jspuser example CREATE DATABASE
[arkwright:~] psql -U jspuser -f jspbook.sql example psql:jspbook.sql:9: NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'user_pk' for table 'employee' CREATE CREATE CREATE
[arkwright:~] psql example Welcome to psql, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit example=# \dt List of relations Name | Type | Owner ------------------+-------+------- employee | table | jspuser employeeprojects | table | jspuser inputtest | table | jspuser (3 rows)
<ora:useDataSource id="example" className="sun.jdbc.odbc.JdbcOdbcDriver" url="jdbc:odbc:example" />
with
<ora:useDataSource id="example" className="org.postgresql.Driver" url="jdbc:postgresql:example?user=jspuser&password=8231" />So, move the the directory ora.The subdirectories from here (ch9, ch10 etc) contain the JSP pages with the default driver details.
[arkwright:~]cd $TOMCAT_HOME/webapps/ora/I did a rather ugly perl-on-the-command-line trick although there are many ways to do a search and replace.. whichever you prefer. =)
perl -pi.bak -e 's/sun.jdbc.odbc.JdbcOdbcDriver/org.postgresql.Driver/g; s/jdbc:odbc:example/jdbc:postgresql:example?user=jspuser&password=8231/g;' `grep -rl sun.jdbc.odbc.JdbcOdbcDriver *`
I've truncated this for readability but it must be one whole line.
This will find each occurence of the default database driver and replace
the text with our new postgres one.
Altered files will be backed-up with the suffix .bak
create table Employee ( UserName varchar(50) constraint user_pk primary key, Password varchar(50), FirstName varchar(50), LastName varchar(50), Dept varchar(50), EmpDate date, EmailAddr varchar(50), ModDate date ); create table EmployeeProjects ( UserName varchar(50), ProjectName varchar(50)); create table InputTest ( MyDate date, MyNumber int);
I couldn't compile the jdbc driver source on my box, I'm not really a java
bod so it was probably my mistake. =)
Apparently the next openBSD port of postgresql will have the jdbc
included.
I seem to have a number of odd permission errors in the $TOMCAT_HOME/work directories where the servelets are generated. I am having difficulty replicating these errors but it's something to be aware of. =)
I would welcome comments or corrections from other people who may have found this helpful or otherwise. =)