|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.buzzsurf.sql.BuzzSQL
com.buzzsurf.sql.Update
public class Update
An Update object modifies rows in a database and queries the number of rows updated. It is a combination of the underlying JDBC classes;
java.sql.Connection
java.sql.PreparedStatement
getUpdateCount() or
getRowCount().
Update object using the automatic
default connection to the database. The SQL statement is passed via constructor, and the arguments are passed using the
setArgs(Object...) method. execute() is called to execute the
database call, and then the update count is queries by calling getUpdateCount(). The object
is then closed to cleanup any resources and return the connection to the pool.
Update update = new Update();
update.setSQL("update example.table_example1 set col_str = ? where col_pk = ?");
update.setArgs("asdf",1);
update.execute();
int updateCount = update.getUpdateCount();
update.close();
Note: This code does not handle exceptions. You normally should wrap your calls in try/catch/finally blocks to handle
any problems. It is advisable to put your close() call in a finally block to insure the
connection is always released.
BuzzSQL| Field Summary | |
|---|---|
protected int |
rowCount
|
| Fields inherited from class com.buzzsurf.sql.BuzzSQL |
|---|
args, con, DATABASE_FORMATTER, dataSourceName, sql, stmt, usingExplicitConnection |
| Constructor Summary | |
|---|---|
Update()
A zero argument constructor is provided for simplified operation with JavBeans, SOAP, and reflection scenarios where having such a constructor is necessary or convenient. |
|
Update(java.lang.String sql)
A single argument constructor that accepts your SQL statement and uses the default DataSource. |
|
Update(java.lang.String sql,
java.sql.Connection con)
A dual argument constructor that accepts your SQL statement and a java.sql.Connection object. |
|
Update(java.lang.String sql,
java.lang.String dataSourceName)
A dual argument constructor that accepts your SQL statement and the explicit name of a DataSource to use. |
|
| Method Summary | |
|---|---|
Update |
execute()
During execution a database connection is obtained (if needed), SQL and arguments are merged, and the PreparedStatement is executed against the database. |
int |
getRowCount()
Get the number of rows updated. |
int |
getUpdateCount()
Get the number of rows updated. |
| Methods inherited from class com.buzzsurf.sql.BuzzSQL |
|---|
addArgs, close, close, getArgs, getConnection, getDataSourceName, getReleaseInfo, getSQL, getStatement, merge, prepare, queryToString, setArgs, setConnection, setDataSourceName, setSQL, usingExplicitConnection |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected int rowCount
| Constructor Detail |
|---|
public Update()
setSQL(String) before execution when using this constructor.
public Update(java.lang.String sql)
sql - The SQL statement
public Update(java.lang.String sql,
java.lang.String dataSourceName)
sql - The SQL statementdataSourceName - The explicit name of the dataSource to obtain a connecton from in DataSourceManager.
public Update(java.lang.String sql,
java.sql.Connection con)
java.sql.Connection object.
This constructor provides a great deal of flexibility by allowing the use of "explicit" connections that are supplied
by the user rather than being obtained automatically by BuzzSQL. Using a explicit connection also allows BuzzSQL to
support database transactions.
sql - The SQL statementcon - The explicit database Connection| Method Detail |
|---|
public int getRowCount()
public int getUpdateCount()
public Update execute()
throws java.sql.SQLException
execute() throws an exception if any of these steps fails
for any reason.
ResultSet and ResultSetMetaData, while Update based objects will
query and save the updated row count to a local variable.
execute() returns a reference to the current object to support method chaining. See
Method Chaining for more information. You can assume execution succeeded if no exception is thrown.
execute in class BuzzSQLjava.sql.SQLException - if any of the executing JDBC operations failed
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||