iglu.jdbc
Class JDBCUtils

java.lang.Object
  |
  +--iglu.jdbc.JDBCUtils

public class JDBCUtils
extends java.lang.Object

General utilities for database access.

Author:
Travis Bauer, Ryan Scherle

Constructor Summary
JDBCUtils()
           
 
Method Summary
static boolean doCommit(java.sql.Connection db)
          Convienence method to do a commit and catch the exception.
static java.sql.ResultSet doSQL(java.sql.Connection db, java.lang.String sqlQuery)
           
static java.lang.Integer firstSqlInt(java.sql.Connection db, java.lang.String sqlQuery)
          returns as an Integer the first field of the first row returned in the sql query.
static java.lang.String firstSqlString(java.sql.Connection db, java.lang.String sqlQuery)
          returns as a string the first field of the first row returned in the sql query.
static void loadPGSQLDriver()
          Forces the PGSQL driver to load.
static java.sql.Connection makeConnection(java.lang.String url, java.lang.String name, java.lang.String password)
          Connects to a database, while providing debugging output.
static int numRows(java.sql.ResultSet rs)
          Returns the number of touples in the result set.
static boolean tryUpdate(java.sql.Connection db, java.lang.String sqlQuery)
          Execute an update.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCUtils

public JDBCUtils()
Method Detail

loadPGSQLDriver

public static void loadPGSQLDriver()
Forces the PGSQL driver to load. The driver should always be org.postgresql.Driver unless the Postgresql people change it.


makeConnection

public static java.sql.Connection makeConnection(java.lang.String url,
                                                 java.lang.String name,
                                                 java.lang.String password)
Connects to a database, while providing debugging output. Sets the database to require explicit commits.

Parameters:
url - The location of the database in the form of jdbc:postgresql://host/databasename
name - Login name of the person connecting to the database.
password - Password of the person connecting.

doSQL

public static java.sql.ResultSet doSQL(java.sql.Connection db,
                                       java.lang.String sqlQuery)

firstSqlString

public static java.lang.String firstSqlString(java.sql.Connection db,
                                              java.lang.String sqlQuery)
returns as a string the first field of the first row returned in the sql query.

Parameters:
db - Database to send the string.
sqlQuery - The query to send.
Returns:
the string mentioned above, or null if the set returns no rows

firstSqlInt

public static java.lang.Integer firstSqlInt(java.sql.Connection db,
                                            java.lang.String sqlQuery)
returns as an Integer the first field of the first row returned in the sql query.

Parameters:
db - Database to send the string.
sqlQuery - The query to send.
Returns:
the Integer mentioned above, or null if the set returns no rows

tryUpdate

public static boolean tryUpdate(java.sql.Connection db,
                                java.lang.String sqlQuery)
Execute an update. Returns true if there was no exception, false if there was. Automatically commits if there was an exception, so future actions don't get erased.


doCommit

public static boolean doCommit(java.sql.Connection db)
Convienence method to do a commit and catch the exception.

Parameters:
db - a Connection value
Returns:
a boolean value

numRows

public static int numRows(java.sql.ResultSet rs)
Returns the number of touples in the result set.