Heng Sin Low 2009-05-20 04:34:18 +00:00
parent ba1efcca46
commit 0876a73879
1 changed files with 204 additions and 106 deletions

View File

@ -853,7 +853,20 @@ public final class DB
*/ */
public static int executeUpdate (String sql, String trxName) public static int executeUpdate (String sql, String trxName)
{ {
return executeUpdate(sql, null, false, trxName); return executeUpdate(sql, trxName, 0);
} // executeUpdate
/**
* Execute Update.
* saves "DBExecuteError" in Log
* @param sql sql
* @param trxName optional transaction name
* @param timeOut optional timeout parameter
* @return number of rows updated or -1 if error
*/
public static int executeUpdate (String sql, String trxName, int timeOut)
{
return executeUpdate(sql, null, false, trxName, timeOut);
} // executeUpdate } // executeUpdate
/** /**
@ -879,9 +892,23 @@ public final class DB
*/ */
public static int executeUpdate (String sql, boolean ignoreError, String trxName) public static int executeUpdate (String sql, boolean ignoreError, String trxName)
{ {
return executeUpdate (sql, null, ignoreError, trxName); return executeUpdate (sql, ignoreError, trxName, 0);
} // executeUpdate } // executeUpdate
/**
* Execute Update.
* saves "DBExecuteError" in Log
* @param sql sql
* @param ignoreError if true, no execution error is reported
* @param trxName transaction
* @param timeOut optional timeOut parameter
* @return number of rows updated or -1 if error
*/
public static int executeUpdate (String sql, boolean ignoreError, String trxName, int timeOut)
{
return executeUpdate (sql, null, ignoreError, trxName, timeOut);
}
/** /**
* Execute Update. * Execute Update.
* saves "DBExecuteError" in Log * saves "DBExecuteError" in Log
@ -892,7 +919,21 @@ public final class DB
*/ */
public static int executeUpdate (String sql, int param, String trxName) public static int executeUpdate (String sql, int param, String trxName)
{ {
return executeUpdate (sql, new Object[]{new Integer(param)}, false, trxName); return executeUpdate (sql, param, trxName, 0);
} // executeUpdate
/**
* Execute Update.
* saves "DBExecuteError" in Log
* @param sql sql
* @param param int param
* @param trxName transaction
* @param timeOut optional timeOut parameter
* @return number of rows updated or -1 if error
*/
public static int executeUpdate (String sql, int param, String trxName, int timeOut)
{
return executeUpdate (sql, new Object[]{new Integer(param)}, false, trxName, timeOut);
} // executeUpdate } // executeUpdate
/** /**
@ -906,7 +947,22 @@ public final class DB
*/ */
public static int executeUpdate (String sql, int param, boolean ignoreError, String trxName) public static int executeUpdate (String sql, int param, boolean ignoreError, String trxName)
{ {
return executeUpdate (sql, new Object[]{new Integer(param)}, ignoreError, trxName); return executeUpdate (sql, param, ignoreError, trxName, 0);
} // executeUpdate
/**
* Execute Update.
* saves "DBExecuteError" in Log
* @param sql sql
* @param param int parameter
* @param ignoreError if true, no execution error is reported
* @param trxName transaction
* @param timeOut optional timeOut parameter
* @return number of rows updated or -1 if error
*/
public static int executeUpdate (String sql, int param, boolean ignoreError, String trxName, int timeOut)
{
return executeUpdate (sql, new Object[]{new Integer(param)}, ignoreError, trxName, timeOut);
} // executeUpdate } // executeUpdate
/** /**
@ -919,6 +975,21 @@ public final class DB
* @return number of rows updated or -1 if error * @return number of rows updated or -1 if error
*/ */
public static int executeUpdate (String sql, Object[] params, boolean ignoreError, String trxName) public static int executeUpdate (String sql, Object[] params, boolean ignoreError, String trxName)
{
return executeUpdate(sql, params, ignoreError, trxName, 0);
}
/**
* Execute Update.
* saves "DBExecuteError" in Log
* @param sql sql
* @param params array of parameters
* @param ignoreError if true, no execution error is reported
* @param trxName optional transaction name
* @param timeOut optional timeOut parameter
* @return number of rows updated or -1 if error
*/
public static int executeUpdate (String sql, Object[] params, boolean ignoreError, String trxName, int timeOut)
{ {
if (sql == null || sql.length() == 0) if (sql == null || sql.length() == 0)
throw new IllegalArgumentException("Required parameter missing - " + sql); throw new IllegalArgumentException("Required parameter missing - " + sql);
@ -930,6 +1001,8 @@ public final class DB
try try
{ {
setParameters(cs, params); setParameters(cs, params);
if (timeOut > 0)
cs.setQueryTimeout(timeOut);
no = cs.executeUpdate(); no = cs.executeUpdate();
// No Transaction - Commit // No Transaction - Commit
if (trxName == null) if (trxName == null)
@ -976,6 +1049,20 @@ public final class DB
* @throws SQLException * @throws SQLException
*/ */
public static int executeUpdateEx (String sql, Object[] params, String trxName) throws DBException public static int executeUpdateEx (String sql, Object[] params, String trxName) throws DBException
{
return executeUpdateEx(sql, params, trxName, 0);
}
/**
* Execute Update and throw exception.
* @param sql
* @param params statement parameters
* @param trxName transaction
* @param timeOut optional timeOut parameter
* @return number of rows updated
* @throws SQLException
*/
public static int executeUpdateEx (String sql, Object[] params, String trxName, int timeOut) throws DBException
{ {
if (sql == null || sql.length() == 0) if (sql == null || sql.length() == 0)
throw new IllegalArgumentException("Required parameter missing - " + sql); throw new IllegalArgumentException("Required parameter missing - " + sql);
@ -987,6 +1074,8 @@ public final class DB
try try
{ {
setParameters(cs, params); setParameters(cs, params);
if (timeOut > 0)
cs.setQueryTimeout(timeOut);
no = cs.executeUpdate(); no = cs.executeUpdate();
// No Transaction - Commit // No Transaction - Commit
if (trxName == null) if (trxName == null)
@ -1038,7 +1127,16 @@ public final class DB
*/ */
public static int executeUpdateEx (String sql, String trxName) throws DBException public static int executeUpdateEx (String sql, String trxName) throws DBException
{ {
return executeUpdateEx(sql, null, trxName); return executeUpdateEx(sql, trxName, 0);
} // executeUpdateEx
/**
* Execute Update and throw exception.
* @see {@link #executeUpdateEx(String, Object[], String)}
*/
public static int executeUpdateEx (String sql, String trxName, int timeOut) throws DBException
{
return executeUpdateEx(sql, null, trxName, timeOut);
} // executeUpdateEx } // executeUpdateEx
/** /**