tylerhayes.tools
Class DatabaseConnector

java.lang.Object
  extended by tylerhayes.tools.DatabaseConnector

public class DatabaseConnector
extends java.lang.Object

The DatabaseConnector class simply makes a connection to a database-- nothing more, nothing less. Currently, only connection to a Postgresql database is implemented.


Constructor Summary
DatabaseConnector()
           
 
Method Summary
static java.sql.Connection connectToPostgres(java.lang.String dbUrl, java.lang.String user, java.lang.String password)
          Connects to a specific Postgresql database with the gievn parameters: database url, user name, and password.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseConnector

public DatabaseConnector()
Method Detail

connectToPostgres

public static java.sql.Connection connectToPostgres(java.lang.String dbUrl,
                                                    java.lang.String user,
                                                    java.lang.String password)
Connects to a specific Postgresql database with the gievn parameters: database url, user name, and password.

In order to connect to a Postgresql database with Java, the JDBC driver is utilized. At the time of this writing (Aug, 2010), the postgresql-8.4-701.jdbc4 jar file for the driver can be downloaded here: http://jdbc.postgresql.org/download.html.

If a connection is unable to be made (an Exception was thrown), the stack trace is output to stdout, and the program will terminate.

Parameters:
dbUrl - The url of the Postgresql database.

Example: "jdbc:postgresql://localhost/dbname"

user - The user name for the database.
password - The password for the database.
Returns:
A Connection object that can be used to communicate to the Postgresql database.