To import a database created at uni, you first need to dump the information into a file readable by PostgreSQL. To do this, in the terminal window type pg_dump -O DBNAME
First, download postgresql from the official website here.
Install postgresql on your local machine. It would be a good idea to use your windows login for your PostgreSQL main login to save you having to log on as a different time you access psql.
Access the command prompt and move to the \Postgresql\8.2\bin\ (this is done automatically if you load 'Command Prompt' in the newly created Postgresql folder in your start menu. To log into postgresql, type psql postgres. This will log you into PostgreSQL.
You can setup a new user from here to allow you to connect as the same username as you use at uni to keep your code as close to what you will need to run on the uni computers. To do this, type Create user USER
Log back in as your new user using the command psql postgres "USER
Now we need to restore the database dump into your local postgresql. Make sure that the dump of your original database is in this directory, and then type psql DBNAME
Getting netbeans set up to connect to PostgreSQL databases
Download the JDBC drivers here. Put the jar file in your Java folder (normally \Program Files\Java\).
Load up netbeans and right click on your project and go to properties. Select Libraries from the left pane and make sure you are in the compile tab. Click Add Jar/Folder and find the JDBC jar file you just saved.
To make a connection in a java method, you first need to call
Class.forName(org.postgresql.Driver);
This tells netbeans which driver to use when creating connections.
When creating a connection, the default url for a locally stored database is
jdbc:postgresql://localhost:5432/DBNAME
1 comment:
I need to make a couple of changes to the database as it is, so if you haven't got a new copy of the database after reading this comment (14.3.07), then you will have to do so. Also, I need to set up priveledges for James and Feng-Ming, so if you can remind me to do this when you see me in the lab, then that would be great.
Post a Comment