org.nsdl.mptstore.util
Class DBUtil

java.lang.Object
  extended by org.nsdl.mptstore.util.DBUtil

public abstract class DBUtil
extends java.lang.Object

Database-related utilities.

Author:
cwilper@cs.cornell.edu

Method Summary
static java.lang.String getLongString(java.sql.ResultSet rs, int pos)
          Get a long string, which could be a TEXT or CLOB type.
static java.lang.String quotedString(java.lang.String in, boolean backslashIsEscape)
          Provide a single-quoted, properly escaped String for the given value to be used in a SQL statement.
static void release(java.sql.Connection conn)
          Ensure the given connection is in auto-commit mode (default) and close/release it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getLongString

public static java.lang.String getLongString(java.sql.ResultSet rs,
                                             int pos)
                                      throws java.sql.SQLException
Get a long string, which could be a TEXT or CLOB type. CLOBs require special handling. This method normalizes the reading of them.

Parameters:
rs - The ResultSet whose current row contains the desired value.
pos - The position (column) of the value in the current row.
Returns:
The desired string, or null if the value in the ResultSet is null.
Throws:
java.sql.SQLException - if there is an database error accessing the value from the ResultSet.

quotedString

public static java.lang.String quotedString(java.lang.String in,
                                            boolean backslashIsEscape)
Provide a single-quoted, properly escaped String for the given value to be used in a SQL statement. Apostrophes will always be escaped as ''. Backslashes will be escaped as \\ if backslashIsEscape is given as true.

Parameters:
in - The input value.
backslashIsEscape - Whether backslash characters are treated as escape characters by the underlying database implementation, and thus need to be escaped themselves.
Returns:
the escaped string.

release

public static void release(java.sql.Connection conn)
Ensure the given connection is in auto-commit mode (default) and close/release it. Any errors encountered will be logged.

Parameters:
conn - the connection.