|
|||||||||
| 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
com.buzzsurf.sql.Delete
public class Delete
An Delete object deletes rows from a database table and queries the number of rows deleted. It is a combination of the underlying JDBC classes;
java.sql.Connection
java.sql.PreparedStatement
getDeleteCount() or
getRowCount().
com.buzzsurf.sql.Delete extends com.buzzsurf.sql.Update, but add only minor functionality
beyond that which is contained in the parent class. Therefore you may choose to use
com.buzzsurf.sql.Update to perform deletes if it helps to streamline your object structure.
Delete 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 delete count is queries by calling getDeleteCount(). The object
is then closed to cleanup any resources and return the connection to the pool.
Delete delete = new Delete();
delete.setSQL("delete from example.table_example1 where col_int = ?");
delete.setArgs(123);
delete.execute();
int deleteCount = update.getDeleteCount();
delete.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,
Update| Field Summary |
|---|
| Fields inherited from class com.buzzsurf.sql.Update |
|---|
rowCount |
| Fields inherited from class com.buzzsurf.sql.BuzzSQL |
|---|
args, con, DATABASE_FORMATTER, dataSourceName, sql, stmt, usingExplicitConnection |
| Constructor Summary | |
|---|---|
Delete()
A zero argument constructor is provided for simplified operation with JavBeans, SOAP, and reflection scenarios where having such a constructor is necessary or convenient. |
|
Delete(java.lang.String sql)
A single argument constructor that accepts your SQL statement and uses the default DataSource. |
|
Delete(java.lang.String sql,
java.sql.Connection con)
A dual argument constructor that accepts your SQL statement and a java.sql.Connection object. |
|
Delete(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 | |
|---|---|
Delete |
execute()
During execution a database connection is obtained (if needed), SQL and arguments are merged, and the PreparedStatement is executed against the database. |
int |
getDeleteCount()
Get the number of rows deleted. |
| Methods inherited from class com.buzzsurf.sql.Update |
|---|
getRowCount, getUpdateCount |
| 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 |
| Constructor Detail |
|---|
public Delete()
setSQL(String) before execution when using this constructor.
public Delete(java.lang.String sql)
sql - The SQL statement
public Delete(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 Delete(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 getDeleteCount()
public Delete 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 Updatejava.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 | ||||||||