|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
This is the central abstraction of the JDBC library, it provides
methods to execute SQL statements. It is implemented by
SQLExecuter to provide non-transactional
access to the database. Transactional access to the database is provided
through a callback mechanism inside the executeTX method of SQLExecuter which
passes another implementation of this interface to the TXCodeBlock.
For details see the TXCodeBlock.
| Method Summary | |
void |
query(java.lang.String prepSql,
FillingCommand cmd,
ResultSetProcessor rsProcessor)
Use this method to execute SQL-Query-Statements such as select from. |
void |
query(java.lang.String sqlStr,
ResultSetProcessor rsProcessor)
Use this method to execute SQL-Query-Statements such as select from. Example: sql.query("SELECT id, name FROM customer WHERE id > 0", new ResultSetIterator() { public void forEachRow(ResultSet rs) throws SQLException { System.out.println(rs.getString("name")); }}); |
int |
singleIntQuery(java.lang.String sqlStmt)
This method is a convenience method for executing a SQL query which has a single row with a single column containing a number as a result. |
int |
singleIntQuery(java.lang.String prepSqlStmt,
FillingCommand cmd)
This method is a convenience method for executing a SQL query which has a single row with a single column containing a number as a result. |
int |
update(java.lang.String sqlStr)
Use this method to execute modifying SQL-statements such as insert into or update. Example: sql.update("INSERT INTO customer (id, name) VALUES (1, 'John Smith')"); |
int |
update(java.lang.String prepSql,
FillingCommand cmd)
Use this method to execute modifying SQL-statements such as insert into or update, with a PreparedStatement. |
| Method Detail |
public int singleIntQuery(java.lang.String sqlStmt)
throws java.sql.SQLException
int nr_customers = sql.singleIntQuery("SELECT COUNT(*) FROM customer");
sqlStr - contains the SQL query
public int singleIntQuery(java.lang.String prepSqlStmt,
FillingCommand cmd)
throws java.sql.SQLException
final int id_threshold = 1;
int some_customers =
sql.singleIntQuery("SELECT COUNT(*) FROM customer WHERE id > ?",
new FillingCommand() {
public void fill(PreparedStatement s) throws SQLException {
s.setInt(1, id_threshold);
}});
sqlStr - contains the SQL querycmd - is called to set the IN parameters of the prepared statement
public void query(java.lang.String sqlStr,
ResultSetProcessor rsProcessor)
throws java.sql.SQLException
sql.query("SELECT id, name FROM customer WHERE id > 0",
new ResultSetIterator() {
public void forEachRow(ResultSet rs) throws SQLException {
System.out.println(rs.getString("name"));
}});
sqlStr - contains the SQL queryrsProcessor - is used to process the ResultSet resulting
from the query. The ResultSet of this SQL-Query will be
handed to the ResultSetProcessor; if an iteration over all
rows of the result set is desired, use a ResultSetIterator
(like in the above example).
public int update(java.lang.String sqlStr)
throws java.sql.SQLException
sql.update("INSERT INTO customer (id, name) VALUES (1, 'John Smith')");
sqlStr - the statement to be executed
public int update(java.lang.String prepSql,
FillingCommand cmd)
throws java.sql.SQLException
final int id = 1;
final String name = "John Smith";
sql.update("INSERT INTO customer (id, name) VALUES (?, ?)",
new FillingCommand() {
public void fill(PreparedStatement s) throws SQLException {
s.setInt(1, id);
s.setString(2, name);
}});
sqlStr - the prepared statement to be executed
public void query(java.lang.String prepSql,
FillingCommand cmd,
ResultSetProcessor rsProcessor)
throws java.sql.SQLException
final int id_threshold = 3;
sql.query("SELECT id, name FROM customer WHERE id > ?",
new FillingCommand() {
public void fill(PreparedStatement s) throws SQLException {
s.setInt(1, id_threshold);
}},
new ResultSetIterator() {
public void forEachRow(ResultSet rs) throws SQLException {
System.out.println(rs.getString("name"));
}});
prepSql - contains the SQL query in the "PreparedStatement" formcmd - is called to set the IN parameters of the prepared statementrsProcessor - is used to process the ResultSet resulting from the query.
The ResultSet of this SQL-Query will be handed to the ResultSetProcessor; if
an iteration over all rows of the result set is desired, use a ResultSetIterator.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||