com.bitmechanic.maxq
Class DBUtil

java.lang.Object
  extended by com.bitmechanic.maxq.DBUtil

public class DBUtil
extends java.lang.Object

Utility class used to simplify database operations from within MaxQ python scripts.


Constructor Summary
DBUtil(java.lang.String driver, java.lang.String url, java.util.Properties props)
          Oopens a database connection using the properties provided.
DBUtil(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String pw)
          Opens a database connection using the parameters provided.
 
Method Summary
 void close()
          Closes the JDBC Connection associated with this instance.
 int execute(java.lang.String sql)
          Executes the INSERT/UPDATE/DELETE statement passed in.
 java.sql.Connection getConnection()
          Returns the JDBC Connection object associated with this object.
 java.util.HashMap loadRow(java.lang.String sql)
          Executes the SELECT statement passed in.
 java.util.ArrayList loadRows(java.lang.String sql)
          Executes the SELECT statement passed in.
 java.lang.String loadVal(java.lang.String sql)
          Executes the SELECT statement passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBUtil

public DBUtil(java.lang.String driver,
              java.lang.String url,
              java.lang.String username,
              java.lang.String pw)
       throws java.lang.Exception
Opens a database connection using the parameters provided. Connection is stored in an instance variable. Call close() to close this connection.

Parameters:
driver - Class name of the JDBC driver to use
url - JDBC URL to connect to
username - Database username to connect as
pw - Database password
Throws:
java.lang.Exception

DBUtil

public DBUtil(java.lang.String driver,
              java.lang.String url,
              java.util.Properties props)
       throws java.lang.Exception
Oopens a database connection using the properties provided. Connection is stored in an instance variable. Call close() to close this connection.

Parameters:
driver - Class name of the JDBC driver to use
url - JDBC URL to connect to
props - JDBC properties to connect with
Throws:
java.lang.Exception
Method Detail

getConnection

public java.sql.Connection getConnection()
Returns the JDBC Connection object associated with this object.


execute

public int execute(java.lang.String sql)
            throws java.lang.Exception
Executes the INSERT/UPDATE/DELETE statement passed in. Returns the number of rows affected by the query.

Throws:
java.lang.Exception

loadRows

public java.util.ArrayList loadRows(java.lang.String sql)
                             throws java.lang.Exception
Executes the SELECT statement passed in. Returns an ArrayList of HashMap objects. One HashMap per row returned. Keys in the HashMap correspond to the columns in the SELECT statement. If the ResultSet is empty, a zero length ArrayList is returned.

Parameters:
sql - SELECT query to run
Throws:
java.lang.Exception

loadRow

public java.util.HashMap loadRow(java.lang.String sql)
                          throws java.lang.Exception
Executes the SELECT statement passed in. Returns a single HashMap object corresponding to the first row in the ResultSet. If the ResultSet is empty, it returns null.

Parameters:
sql - SELECT query to run.
Throws:
java.lang.Exception

loadVal

public java.lang.String loadVal(java.lang.String sql)
                         throws java.lang.Exception
Executes the SELECT statement passed in. Returns the first column of the first row in the ResultSet. If the ResultSet is empty, it returns null.

Parameters:
sql - SELECT query to run
Throws:
java.lang.Exception

close

public void close()
           throws java.lang.Exception
Closes the JDBC Connection associated with this instance. Call this when you're done with this object. After calling this method, no other methods will work.

Throws:
java.lang.Exception