Wednesday, March 28, 2007

connect openoffice to postgresql database

OpenOffice is useful to view remote database server.

First, create a database role to only view the remote database:
(1)#create role peter login;
(2)#alter role peter with password '12345';
(3)#grant select on table tablename to peter;
(4)modify pg_hba.conf file so that it includes line: (this line must be positioned so that it is the first to match for the connection request).
host dbname peter2 192.168.1.0/24 password
(5)reload the configuration
(6)test with psql -U peter -h hostip -W dbname

Second, OpenOffice configuration:
(1)Make sure Java (http://java.sun.com) is installed in the computer
(2)Download & Install OpenOffice 2.x.
(3)Download jdbc driver for PostgreSQL. (http://jdbc.postgresql.org)
(4)Run OpenOffice. Navigate to: Tools-->Options-->Java. Select Java and set the CLASSPATH so that the CLASSPATH include the downloaded JDBC driver file. And ok.
(5)Navigate: File-->New-->Database. Select :Connecting to an existing database by JDBC. And use jdbc:postgresql://databasehostip:5432/databasename as databaseURL and org.postgresql.Driver as JDBC driver class. And then type your database username and select "Password required".

That is all.

No comments: