|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjodd.db.SqlUtil
Smart-and-slick SQL facade. Class is not fool-proof and threadsafe.
PreparedStatement
setXXX() methodsConstructor Summary | |
SqlUtil(java.sql.Connection conenction)
Default constructor from common Connection. |
|
SqlUtil(ConnectionPool cp)
Default constructor from ConnectionPool. |
Method Summary | |
void |
close()
Closes result set (if previously created) and the statement. |
void |
close(java.sql.ResultSet rs)
Deprecated. use close() instead |
void |
closeAll()
Closes result set (if created), statements and returns connection to db pool when no ResultSets are used. |
void |
closeAll(java.sql.ResultSet rs)
Deprecated. use closeAll() instead. |
void |
commit()
Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by this object. |
java.sql.ResultSet |
executeQuery()
Executes SELECT statements, but works with all statements. |
int |
executeUpdate()
Executes UPDATE, INSERT or DELETE statements. |
java.lang.Boolean |
getAutoCommit()
Retrieves the current auto-commit mode for this object. |
static boolean |
getDebugMode()
Returns current debug mode. |
static java.lang.Boolean |
getDefaultAutoCommit()
Returns default auto-commit mode or null if nothing set. |
java.lang.Boolean |
getStoredAutoCommit()
Returns the stored auto-commit mode for the connection. |
void |
rollback()
Undoes all changes made in the current transaction and releases any database locks currently held by this object. |
void |
setArray(int ndx,
java.sql.Array value)
Sets value of Array parameter in sql string. |
void |
setAutoCommit(boolean autoCommit)
Sets this connection's auto-commit mode to the given state. |
void |
setBigDecimal(int ndx,
java.math.BigDecimal value)
Sets value of BigDecimal parameter in sql string. |
void |
setBlob(int ndx,
java.sql.Blob value)
Sets value of Blob parameter in sql string. |
void |
setBoolean(int ndx,
boolean value)
Sets value of boolean parameter in sql string. |
void |
setByte(int ndx,
byte value)
Sets value of byte parameter in sql string. |
void |
setClob(int ndx,
java.sql.Clob value)
Sets value of Clob parameter in sql string. |
void |
setDate(int ndx,
java.sql.Date value)
Sets value of java.sql.Date parameter in sql string. |
static void |
setDebugMode(boolean b)
Sets debug mode. |
static void |
setDefaultAutoCommit(boolean autoCommit)
Sets default auto-commit that SqlUtil must provide before executing new statement, neverness if setAutoCommit is used or not. |
void |
setDouble(int ndx,
double value)
Sets value of double parameter in sql string. |
void |
setFloat(int ndx,
float value)
Sets value of float parameter in sql string. |
void |
setInt(int ndx,
int value)
Sets value of int parameter in sql string. |
void |
setLong(int ndx,
long value)
Sets value of long parameter in sql string. |
void |
setSql(java.lang.String sql)
Sets and prepares a SQL command by using forward only and read only prepared statement. |
void |
setSql(java.lang.String sql,
int resultType,
int resultSetConcurrency)
Sets and prepares a SQL command by using prepared statements. |
void |
setStaticSql(java.lang.String sql)
Sets and prepares a SQL command by using forward only and read only statement. |
void |
setStaticSql(java.lang.String sql,
int resultType,
int resultSetConcurrency)
Sets and prepares a SQL command by using simple statements. |
void |
setString(int ndx,
java.lang.String value)
Sets value of String parameter in sql string. |
void |
setTimestamp(int ndx,
java.sql.Timestamp value)
Sets value of java.sql.Timestamp parameter in sql string. |
java.lang.String |
toString()
Returns formated pseudo-SQL string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public SqlUtil(ConnectionPool cp)
cp
- connection pool instancepublic SqlUtil(java.sql.Connection conenction)
conenction
- opened db connectionMethod Detail |
public void setSql(java.lang.String sql) throws java.sql.SQLException
sql
- sql query string.
java.sql.SQLException
setSql(String, int, int)
public void setSql(java.lang.String sql, int resultType, int resultSetConcurrency) throws java.sql.SQLException
It first closes existing resultset, if any availiable. Then it closes existing prepared statement. After, obtains connection from database if not already taken. Sets commit mode, if necessary.
sql
- sql query string.resultType
- result typeresultSetConcurrency
- result concurrency
java.sql.SQLException
public void setStaticSql(java.lang.String sql) throws java.sql.SQLException
sql
- sql query string.
java.sql.SQLException
setStaticSql(String, int, int)
public void setStaticSql(java.lang.String sql, int resultType, int resultSetConcurrency) throws java.sql.SQLException
It first closes existing resultset, if any availiable. Then it closes existing statement. After, obtains connection from database if not already taken. Sets commit mode, if necessary.
sql
- sql query string.resultType
- result typeresultSetConcurrency
- concurency type
java.sql.SQLException
public java.sql.ResultSet executeQuery() throws java.sql.SQLException
java.sql.SQLException
public int executeUpdate() throws java.sql.SQLException
java.sql.SQLException
public void close(java.sql.ResultSet rs)
rs
- ResultSet created by executeQuery(), or null if ResultSet is not being used.close()
public void close()
public void closeAll(java.sql.ResultSet rs)
rs
- ResultSet created by executeQuery(), or null if ResultSet is not being used.public void closeAll()
public static void setDefaultAutoCommit(boolean autoCommit)
setAutoCommit
is used or not. By
using this method and setting default auto-commit value to be the same as
it is for database, it is guaranteed that if it is not explicitly set
different, the default mode will be used.
If default auto-commit mode is not used, connection will be examined on first usage, and that commit status will be taken as the default one.
autoCommit
- default auto-commit modepublic static java.lang.Boolean getDefaultAutoCommit()
null
if nothing set.
public void setAutoCommit(boolean autoCommit) throws java.sql.SQLException
commit
or the method rollback
.
If this method is not used, then default database commit mode is used, and this class doesn't change anything.
NOTE: if this method is called before very first
setSql()
or setStaticSql()
, than it will just
'remember' the commit state that will be actually set in those commands,
after connection is retrieved from database. This is prefered method.
If it is called after, then this method will directly change connection commit mode, with all consequences.
autoCommit
- true to enable auto-commit mode; false to disable it
java.sql.SQLException
public java.lang.Boolean getAutoCommit()
null
is returned then default database mode is used.
public java.lang.Boolean getStoredAutoCommit()
null
is returned, then
connection is not yet obtained. Therefore, this method has to be called
after setSql
methods.
public void commit() throws java.sql.SQLException
java.sql.SQLException
public void rollback()
public static void setDebugMode(boolean b)
b
- public static boolean getDebugMode()
public java.lang.String toString()
PreparedStatement
is used, all ? are replaced with String representation of assigned values.
Just for debugging purposes.
public void setInt(int ndx, int value) throws java.sql.SQLException
ndx
- 1-based index od parametervalue
- int value
java.sql.SQLException
public void setBoolean(int ndx, boolean value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
public void setLong(int ndx, long value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
public void setByte(int ndx, byte value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
public void setDouble(int ndx, double value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
public void setFloat(int ndx, float value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
public void setString(int ndx, java.lang.String value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
public void setDate(int ndx, java.sql.Date value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
public void setTimestamp(int ndx, java.sql.Timestamp value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
public void setArray(int ndx, java.sql.Array value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
public void setBigDecimal(int ndx, java.math.BigDecimal value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
public void setBlob(int ndx, java.sql.Blob value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
public void setClob(int ndx, java.sql.Clob value) throws java.sql.SQLException
ndx
- 1-based index of parametervalue
- parameter value
java.sql.SQLException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |