|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.is.util.sql.JDBCHelper
Instances of this class execute JDBC queries and give access to data columns.
Note: **AutoCommit has been turned off**. You must explicitly call commit() or rollback(). (If you do not, the close method will commit any uncommitted transactions).
Vector result = new Vector(20);
JDBCHelper helper = null;
try
{
helper = new JDBCHelper("weblogic.jdbc.pool.Driver",
"jdbc:weblogic:pool",
"myPool");
helper.executeQuery("SELECT * FROM Status");
while (helper.next())
{
StatusValue aStatusValue =
new StatusValue(helper.getInteger("StatusId"));
aStatusValue.setCode(helper.getString("Code"));
aStatusValue.setActive(helper.getboolean("Active"));
aStatusValue.setSortOrder(helper.getint("SortOrder"));
result.addElement(aStatusValue);
} // while
helper.close();
}
catch (SQLException e)
{
LOG.error(
"***SQLException - Column name: " + helper.getColumnName());
e.printStackTrace();
throw e;
}
catch (Exception e)
{
LOG.error("Exception caught in Xyx.abc()", e);
e.printStackTrace();
throw e;
}
Quick summary of the column value getter methods:
(This is here to show the naming convention)
method name | return type |
---|---|
getint | int |
getInteger | Integer or null |
getlong | long |
getLong | Long |
getShort | Short |
getboolean | boolean |
getBoolean | Boolean |
getNullableBoolean | Boolean or null |
getfloat | float |
getFloat | Float or null |
getdouble | double |
getDouble | Double |
getString | trimmed String or null |
getRawString | String or null |
getDate | java.sql.Date or null |
getTime | java.sql.Time or null |
getTimestamp | java.sql.Timestamp or null |
getBigDecimal | BigDecimal |
Field Summary | |
static java.lang.String |
DOUBLE_QUOTE
The delimiter characters - double quote. |
static int |
s_instanceCount
|
static java.lang.String |
SINGLE_QUOTE
The delimiter characters - single quote. |
Constructor Summary | |
JDBCHelper(javax.sql.DataSource dataSource)
Create a JDBC helper that will use the supplied information to get a connection from a JDBC connection pool. |
|
JDBCHelper(java.lang.String dataSourceName)
Create a JDBC helper that will use the supplied information to get a connection from a JDBC connection pool. |
|
JDBCHelper(java.lang.String driverClass,
java.lang.String url,
java.lang.String poolName)
Deprecated. Use J2EE DataSource instead |
|
JDBCHelper(java.lang.String driverClass,
java.lang.String url,
java.lang.String user,
java.lang.String password)
Deprecated. Use J2EE DataSource instead |
Method Summary | |
void |
beginTransaction()
Calling this method tells JDBCHelper to ignore commit() messages and close() messages until endTransaction() is called. |
java.lang.Object |
clone()
Return a copy of myself without a database connection. |
void |
close()
Close the result set, statement, and connection. |
void |
commit()
Commit the transaction. |
static java.lang.String |
delimitDoubleQuote(java.lang.String p_val)
Formats a String for use as a String in a DB query where a double quote is the delimiter. |
static java.lang.String |
delimitSingleQuote(java.lang.String p_val)
Formats a String for use as a String in a DB query where a single quote is the delimiter. |
static java.lang.String |
delimitString(java.lang.String p_val,
java.lang.String p_delimiter)
STATIC CLASS METHOD: Formats a String for use as a String in a DB query where the delimiter is as provided. |
void |
endTransaction()
This method turns off the isInsideTransaction flag and commits the database changes. |
void |
executeQuery(java.sql.PreparedStatement stmt)
Executes a prepared statement created by prepareStatement(). |
void |
executeQuery(java.lang.String sqlString)
Execute the SQL string. |
int |
executeUpdate(java.sql.PreparedStatement stmt)
Execute an update/insert/delete on a PreparedStatement |
int |
executeUpdate(java.lang.String sqlString)
Execute an update/insert/delete. |
java.math.BigDecimal |
getBigDecimal(int column)
Calls the getBigDecimal() method on the ResultSet. |
java.math.BigDecimal |
getBigDecimal(java.lang.String column)
Calls the getBigDecimal() method on the ResultSet. |
boolean |
getboolean(int column)
Calls the getboolean() method on the ResultSet. |
java.lang.Boolean |
getBoolean(int column)
Calls the getBoolean() method on the ResultSet and wraps the boolean in a Boolean. |
boolean |
getboolean(java.lang.String column)
Calls the getBoolean() method on the ResultSet. |
java.lang.Boolean |
getBoolean(java.lang.String column)
Calls the getBoolean() method on the ResultSet and wraps the boolean in a Boolean. |
byte[] |
getBytes(int column)
Calls the getBytes() method on the ResultSet. |
byte[] |
getBytes(java.lang.String column)
Calls the getBytes() method on the ResultSet. |
boolean |
getCloseButDontCommit()
Return whether the commit() method should actually commit or not. |
java.lang.String |
getColumnName()
Return the name of the column that was unsuccessfully accessed. |
boolean |
getCommitButDontClose()
Return whether the close() method should actually close the connection or not. |
java.sql.Connection |
getConnection()
Return the current Connection. |
java.sql.Date |
getDate(int column)
Calls the getDate() method on the ResultSet. |
java.sql.Date |
getDate(java.lang.String column)
Calls the getDate() method on the ResultSet. |
double |
getdouble(int column)
Calls the getDouble() method on the ResultSet. |
java.lang.Double |
getDouble(int column)
Calls the getDouble() method on the ResultSet and wraps the resulting double in a Double. |
double |
getdouble(java.lang.String column)
Calls the getDouble() method on the ResultSet. |
java.lang.Double |
getDouble(java.lang.String column)
Calls the getDouble() method on the ResultSet and wraps the resulting double in a Double. |
float |
getfloat(int column)
Calls the getFloat() method on the ResultSet. |
java.lang.Float |
getFloat(int column)
Calls the getFloat() method on the ResultSet and wraps the resulting float in a Float. |
float |
getfloat(java.lang.String column)
Calls the getFloat() method on the ResultSet. |
java.lang.Float |
getFloat(java.lang.String column)
Calls the getFloat() method on the ResultSet and wraps the resulting float in a Float. |
int |
getint(int column)
Calls the getInt() method on the ResultSet. |
int |
getint(java.lang.String column)
Calls the getInt() method on the ResultSet. |
java.lang.Integer |
getInteger(int column)
Calls the getInt() method on the ResultSet and wraps the resulting int in an Integer. |
java.lang.Integer |
getInteger(java.lang.String column)
Calls the getInt() method on the ResultSet and wraps the resulting int in an Integer. |
JDBCHelperPool |
getJDBCHelperPool()
|
long |
getlong(int column)
Calls the getLong() method on the ResultSet. |
java.lang.Long |
getLong(int column)
Calls the getLong() method on the ResultSet and wraps the resulting long in a Long. |
long |
getlong(java.lang.String column)
Calls the getLong() method on the ResultSet. |
java.lang.Long |
getLong(java.lang.String column)
Calls the getLong() method on the ResultSet and wraps the resulting long in a Long. |
java.lang.Boolean |
getNullableBoolean(int column)
Calls the getBoolean() method on the ResultSet and wraps the boolean in a Boolean. |
java.lang.Boolean |
getNullableBoolean(java.lang.String column)
Calls the getBoolean() method on the ResultSet and wraps the boolean in a Boolean. |
java.lang.Object |
getObject(int column)
Get whatever type of object is in the given column. |
java.lang.Object |
getObject(java.lang.String column)
Get whatever type of object is in the given column. |
java.lang.String |
getRawString(int column)
Calls the getString() method on the ResultSet. |
java.lang.String |
getRawString(java.lang.String column)
Calls the getString() method on the ResultSet. |
java.sql.ResultSet |
getResultSet()
Return the current ResultSet |
boolean |
getReuseStatement()
Return the value of reuseStatement. |
java.lang.Short |
getShort(int column)
Calls the getShort() method on the ResultSet and wraps the resulting in a Short. |
java.lang.Short |
getShort(java.lang.String column)
Calls the getShort() method on the ResultSet and wraps the result in a Short. |
boolean |
getShouldAutoCommit()
Return the value of shouldAutoCommit. |
boolean |
getShouldCommitOnClose()
Return the value of shouldCommitOnClose. |
java.lang.String |
getSQLString()
Return the SQL string that was last executed. |
java.sql.Statement |
getStatement()
Return the statement last used. |
java.lang.String |
getString(int column)
Calls the getString() method on the ResultSet and trims the result. |
java.lang.String |
getString(java.lang.String column)
Calls the getString() method on the ResultSet and trims the result. |
java.sql.Time |
getTime(int column)
Calls the getTime() method on the ResultSet. |
java.sql.Time |
getTime(java.lang.String column)
Calls the getTime() method on the ResultSet. |
java.sql.Timestamp |
getTimestamp(int column)
Calls the getTimestamp() method on the ResultSet. |
java.sql.Timestamp |
getTimestamp(java.lang.String column)
Calls the getTimestamp() method on the ResultSet. |
boolean |
isConnectionClosed()
Answer true if the connection is closed. |
boolean |
isInPool()
|
boolean |
isInsideTransaction()
Return boolean informing us whether we are inside a "transaction" or not. |
void |
markInPool()
After this method is called, this JDBCHelper cannot be used until markOutOfPool() is called. |
void |
markOutOfPool()
|
boolean |
next()
Move the cursor to the next row in the result set. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sqlStatement)
Gets a PreparedStatement for use with executeQuery(aPreparedStatement). |
void |
printColumnNames()
Print the column names returned in the result set out to System.out. |
static java.lang.String |
replace(java.lang.String content,
java.lang.String oldString,
java.lang.String newString)
This method should really be in a StringUtil class. |
void |
returnToPool()
|
void |
rollback()
Rollback the transaction. |
void |
setCloseButDontCommit(boolean v)
Set the value of commitButDontClose. |
void |
setCommitButDontClose(boolean v)
Set the value of commitButDontClose. |
void |
setJDBCHelperPool(JDBCHelperPool v)
|
void |
setReuseStatement(boolean v)
Set the value of reuseStatement. |
void |
setShouldAutoCommit(boolean v)
Set the value of shouldAutoCommit. |
void |
setShouldCommitOnClose(boolean v)
Set the value of shouldCommitOnClose. |
static java.lang.String |
toSQLList(java.util.List objects)
This method should really be in a StringUtil class. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String SINGLE_QUOTE
public static final java.lang.String DOUBLE_QUOTE
public static int s_instanceCount
Constructor Detail |
public JDBCHelper(java.lang.String driverClass, java.lang.String url, java.lang.String poolName)
poolName
- a value of type 'String'public JDBCHelper(javax.sql.DataSource dataSource)
poolName
- a value of type 'String'public JDBCHelper(java.lang.String dataSourceName)
poolName
- a value of type 'String'public JDBCHelper(java.lang.String driverClass, java.lang.String url, java.lang.String user, java.lang.String password)
poolName
- a value of type 'String'Method Detail |
public boolean getCommitButDontClose()
public void setCommitButDontClose(boolean v)
v
- Value to assign to shouldClose.public boolean getCloseButDontCommit()
public void setCloseButDontCommit(boolean v)
v
- Value to assign to shouldClose.public boolean getShouldCommitOnClose()
public void setShouldCommitOnClose(boolean v)
v
- Value to assign to shouldCommitOnClose.public boolean getShouldAutoCommit()
public void setShouldAutoCommit(boolean v)
v
- Value to assign to shouldAutoCommit.public boolean getReuseStatement()
public void setReuseStatement(boolean v)
v
- Value to assign to reuseStatement.public java.sql.Statement getStatement()
public boolean isInsideTransaction()
public JDBCHelperPool getJDBCHelperPool()
public void setJDBCHelperPool(JDBCHelperPool v)
public void returnToPool()
public void executeQuery(java.lang.String sqlString) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, javax.naming.NamingException, java.sql.SQLException
sqlString
- a value of type 'String'java.sql.SQLException
- if a database access error occurspublic java.sql.PreparedStatement prepareStatement(java.lang.String sqlStatement) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, javax.naming.NamingException, java.sql.SQLException
sqlStatement
- a SQL statement that may contain one or more '?' IN
parameter placeholderspublic void executeQuery(java.sql.PreparedStatement stmt) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, javax.naming.NamingException, java.sql.SQLException
stmt
- prepared statement to execute. All IN parameter values
must have been set.java.sql.SQLException
- if an error occurspublic int executeUpdate(java.lang.String sqlString) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, javax.naming.NamingException, java.sql.SQLException
sqlString
- a value of type 'String'java.sql.SQLException
- if an error occurspublic int executeUpdate(java.sql.PreparedStatement stmt) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, javax.naming.NamingException, java.sql.SQLException
sqlString
- a value of type 'String'java.sql.SQLException
- if an error occurspublic boolean isConnectionClosed() throws java.sql.SQLException
public java.sql.Connection getConnection() throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, javax.naming.NamingException, java.sql.SQLException
public java.sql.ResultSet getResultSet()
public boolean next() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurspublic void close() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurspublic void commit() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurspublic void rollback() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurspublic void beginTransaction() throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, javax.naming.NamingException, java.sql.SQLException
public void endTransaction() throws java.sql.SQLException
java.sql.SQLException
- if an error occurspublic java.lang.String getColumnName()
public java.lang.String getSQLString()
public void markInPool()
public void markOutOfPool()
public boolean isInPool()
public void printColumnNames()
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
public java.lang.Object getObject(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'public java.lang.Object getObject(int column) throws java.sql.SQLException
column
- a value of type 'int'public boolean getboolean(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic boolean getboolean(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.lang.Boolean getBoolean(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic java.lang.Boolean getBoolean(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.lang.Boolean getNullableBoolean(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic java.lang.Boolean getNullableBoolean(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.lang.String getString(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundgetRawString(java.lang.String)
public java.lang.String getString(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundgetRawString(java.lang.String)
public java.lang.String getRawString(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic java.lang.String getRawString(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.sql.Timestamp getTimestamp(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic java.sql.Timestamp getTimestamp(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.sql.Date getDate(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic java.sql.Date getDate(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.sql.Time getTime(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic java.sql.Time getTime(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.lang.Integer getInteger(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic java.lang.Integer getInteger(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.lang.Long getLong(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic java.lang.Long getLong(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic int getint(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic int getint(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic long getlong(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic long getlong(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.lang.Short getShort(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic java.lang.Short getShort(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.lang.Float getFloat(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic java.lang.Float getFloat(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic float getfloat(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic float getfloat(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.lang.Double getDouble(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic java.lang.Double getDouble(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic double getdouble(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic double getdouble(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic java.math.BigDecimal getBigDecimal(java.lang.String column) throws java.sql.SQLException
column
- a value of type Stringjava.sql.SQLException
- if column is not foundpublic java.math.BigDecimal getBigDecimal(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic byte[] getBytes(int column) throws java.sql.SQLException
column
- a value of type 'int'java.sql.SQLException
- if column is not foundpublic byte[] getBytes(java.lang.String column) throws java.sql.SQLException
column
- a value of type 'String'java.sql.SQLException
- if column is not foundpublic static java.lang.String delimitSingleQuote(java.lang.String p_val)
p_val
- the String to formatdelimitString(java.lang.String, java.lang.String)
public static java.lang.String delimitDoubleQuote(java.lang.String p_val)
p_val
- the String to formatdelimitString(java.lang.String, java.lang.String)
public static java.lang.String delimitString(java.lang.String p_val, java.lang.String p_delimiter)
p_val
- the String to formatp_delimiter
- the delimiter for formattingpublic static java.lang.String replace(java.lang.String content, java.lang.String oldString, java.lang.String newString)
content
- The text String that will be acted upon (strings
replaced).oldString
- The string that will be replaced.newString
- The string that will replace oldString.public static java.lang.String toSQLList(java.util.List objects)
objects
- a value of type 'List'public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |