Setting up with PostgreSQL

PostgreSQL is an object-relational database system, ORDBS, cross platform, and like MySQL, is also open-source and free. It is supported by a consortium of companies and names like Red Hat, Skype, and HP listed at their website.

As with MySQL, PostgreSQL also features a GUI for management called PGAdmin.

Setting up PostgreSQL with NetBeans is not as straightforward as with MySQL, but NetBeans still comes with the appropriate JDBC driver, so don't worry, it is still no rocket science.

Getting ready

For this recipe, we will use PostgreSQL version 8.4.4 and PGAdmin version 3.

Installation and configuration of PostgreSQL and components onto the Operating System is beyond the scope of this recipe. What will be learned here is how to configure PostgreSQL with NetBeans so that integration between the database and the IDE can be achieved.

In this recipe, we assume that the Database is installed locally and that the password is chosen by the user.

It is necessary to have an existing database in PostgreSQL for this recipe to work; we will assume that the name of the database is mydb.

How to do it...

With the IDE open, and PostgreSQL running:

  1. Navigate to the Services window, right-click on the Databases node, and select New Connection.... When the New Connection Wizard window opens, select PostgreSQL from the dropdown menu, click Next > and enter the following information:
    • Host: 127.0.0.1
    • Port: 5432
    • Database: mydb
    • User Name: postgres
    • Password: postgres
    • Select the Show JDBC URL checkbox
  2. The Basic setting tab should look like this:
    How to do it...
  3. Click on Finish.
  4. On the Advanced tab, click on the Select Schema drop-down and choose public, and then click OK.
  5. A PostgreSQL connection node is added to Databases.
How to do it...

How it works...

NetBeans validates the entered information to access the database. This ensures that no misconfigured database is going to be used and prevents the user to actually create a a misconfigured connection and even prevents the user to proceed further in the wizard.

When Finish is clicked, NetBeans then connects to the PostgreSQL and fetches existing databases from the server. A new Database connection is placed under the Databases subsection of the Services tab.

There's more...

How to connect and disconnect PostgreSQL from within NetBeans?

Connecting and disconnecting

It is possible to connect to and disconnect from a database using the Services window.

Simply right-click on the desired connection and select Connect…, in case the database is disconnected, or Disconnect, if it is connected.

Connecting and disconnecting
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.55.170