PostgreSQL



Working with a Database
The database system is very properly the central part of what we do with server side programming. So we cover this topic first, even though it is not strictly part of J2EE. We see the steps in working with a relational database as follows: (A relational database is one in which data is represented by linked tables).

Choose a Database
We use PostgreSQL as our example. It is a popular open source database. The website is www.postgresql.org. You may choose another open source database such as MySQL, (it has an optional not inexpensive commercial component), or a purely commercial one such as Oracle.

The criteria that are bandied about the most are "stability" and "performance". The all important question is  :- do the "open source" databases such as PostgreSQL match the partly commercial ones such as MySQL or the purely commercial ones such as Oracle? PostgreSQL gets credit for being "heavy duty" or "industrial strength" or even "infrastructure ready".

It's difficult to say. You choose your database and hope for the best. It's very difficult to arrange objective benchmarks or tests - even for hardware components such as CPUs. If you want "proof by intimidation" of this latest comment - I spent half a semester in college substantiating the subtleties involved in  measuring processor speed for CPUs in an accurate way.

My suggestion is that you try inexpensive workable stuff before you deploy the blank checks.

Installing PostgreSQL
Download the binaries from http://www.postgresql.org. The latest version as of this writing is 8.2.4.

Unzip the zipped file into its own directory. Double click on the MSI installer to run the Windows installation program, or the equivalent on Linux or the Mac. You must unzip to a directory on your computer - you cannot run the installer from within the zip file.

Click "Next" on a series of installation screens or whatever value you want to set.

Finally, you will come to a screen that asks you for the account name and password you want to set for the PostgreSQL service you are creating. The title of this screen is "Service Configuration". Enter these values - name and password - and leave the "Install as a service" checkbox checked.  You will find later that this is very useful for running PostgreSQL - by turning it on, off, or auto as a service.

That's all there is to installing PostgreSQL. If you've been following along, you would have installed PostgreSQL by now. You'll have to use your judgement since there are a wide variety of options. If you run into trouble, ask a local guru or system administrator to help you.

This link shows you the sequence of screens the installer gives you while installing.

Write the name of the service name and password somewhere safe. If you forget this, there is no way for you to access your PostgreSQL installation. For you to be able to use your password again is as important making sure no malicious or careless person gets it in connection with your database.

Play and Experiment with the new running Relational Database
Create some tables, add some dummy data, write some queries, that sort of stuff. It's the best way to stop being afraid of your database soon.
    
If you have installed PostgreSQL, start the client - pgAdmin, and create a database and some tables. If you're following along, do this now. You will need the previously entered password right here.

Drill down to PostgreSQL Server 8.2/Databases(1)/dbname/schemas/public/tables
 - create and define a table, and add some data to it and query it using SQL.

This link shows you how - the relevant screens.

If you don't know SQL, the following links could help:
http://sqlzoo.net
http://sqlcourse.com

A detailed description of SQL is outside the scope of this discussion.

You can run queries within and from the GUI pgAdmin tool by going to the "Query Tool" item in the Tools menu selection of the pgAdmin user interface program.
    
Create and Run a new Schema Script
It is best to put the definition of your schema - the tables and constraints - in a script file that you can modify offline and run at once to update your schema. This is really a necessity. The alternative is to remember the database schema in your mind permanently and alter it from your mind forever.
    
There are some essentials that go beyond having the latest whiz-bang framework and this is one of them.
    
Create and Run a new Initialize Data Script
All your new data should be a sequence of "INSERT" statements in a script file. The database lets you "dump" itself into such  a file. But it is a best practice that the very first insertion of your live data into the database should happen from a script.

Remember the Password
To recap, please remember the root password of the Service you set up in MySQL, PostgreSQL, or any other database. You will need it for connecting to your database from your Java code wherever that be.
    
Demo iBATIS and JDBC Connectivity to yourself and to your Satisfaction
Satisfaction is the last word in all this. Once you complete this last step your database is up and ready to use.  It appears that the last word is "use".