| java.lang.Object dinamica.Db
Db | public class Db (Code) | | Core-level framework class: Text Generator.
Encapsulates the JDBC API most common operations
with safe and efficient code. Uses the same connection
for all its operations. Does not close connections, that is the
responsability of the caller (Transaction Manager)
Creation date: 12/09/2003
Last Update: 12/09/2003
(c) 2003 Martin Cordova
This code is released under the LGPL license
author: Martin Cordova (dinamica@martincordova.com) |
Method Summary | |
public void | addBatchCommand(String sql) | public int | exec(String sql) | public int[] | exec() | public int | exec(String sql, Recordset rs, String[] params) Execute prepared statement using a recordset; only the current record is used
Parameters: sql - SQL command to precompile Parameters: rs - Recordset containing the values to be set into the prepared statement Parameters: params - Array containing the names of the fields to use. | public int[] | execBatch(String sql, Recordset rs, String[] params) Execute batch prepared statement using a recordset; all the records are used
Parameters: sql - SQL command to precompile Parameters: rs - Recordset containing the values to be set into the prepared statement Parameters: params - Array containing the names of the fields to use. | public Recordset | get(String sql) Creates a recordset given a SQL query. | public Recordset | get(String sql, int limit) Creates a recordset given a SQL query. | public Object | getColValue(String sql, String columnName) | public double | getDoubleColValue(String sql, String columnName) | public int | getIntColValue(String sql, String columnName) | public void | saveBlob(String sql, String path) Save binary file to blob column using a prepared statement.
The prepared statement must contain only one dynamic parameter (?),
and it must correspond to the BLOB column. | public void | setLogWriter(PrintWriter writer) Set the log writer. |
addBatchCommand | public void addBatchCommand(String sql)(Code) | | Add sql to list of commands to be executed
in batch using the method exec()
Parameters: sql - SQL Command (insert, update or delete) |
exec | public int exec(String sql) throws Throwable(Code) | | Execute an action query (inserts, updates, deletes)
Parameters: sql - SQL command to execute The number of rows affected throws: Throwable - |
exec | public int[] exec() throws Throwable(Code) | | Execute commands in batch - the commands must be previously loaded
into this object using the method addBatchCommand()
Parameters: sql - SQL command to execute Array where each element contains the number of rows affected for each statement throws: Throwable - |
exec | public int exec(String sql, Recordset rs, String[] params) throws Throwable(Code) | | Execute prepared statement using a recordset; only the current record is used
Parameters: sql - SQL command to precompile Parameters: rs - Recordset containing the values to be set into the prepared statement Parameters: params - Array containing the names of the fields to use. The order must match the place holders (those ? marks) in the prepared statement The number of records affected throws: Throwable - - if the params array contains no elements or contains more elements than the recordset field count |
execBatch | public int[] execBatch(String sql, Recordset rs, String[] params) throws Throwable(Code) | | Execute batch prepared statement using a recordset; all the records are used
Parameters: sql - SQL command to precompile Parameters: rs - Recordset containing the values to be set into the prepared statement Parameters: params - Array containing the names of the fields to use. The order must match the place holders (those ? marks) in the prepared statement The number of records affected throws: Throwable - - if the params array contains no elements or contains more elements than the recordset field count |
get | public Recordset get(String sql) throws Throwable(Code) | | Creates a recordset given a SQL query.
Parameters: conn - Database Connection Parameters: sql - SQL Query that returns a Resultset throws: Throwable - |
get | public Recordset get(String sql, int limit) throws Throwable(Code) | | Creates a recordset given a SQL query.
Parameters: conn - Database Connection Parameters: sql - SQL Query that returns a Resultset Parameters: limit - Maximum number of rows to read from the DataBase throws: Throwable - |
getColValue | public Object getColValue(String sql, String columnName) throws Throwable(Code) | | Execute query and return value of a given column
Parameters: sql - Query to execute and retrieve a recordset Parameters: columnName - Name of the column whose value will be retrieved Value of column as Object or null if recordset is empty throws: Throwable - |
getDoubleColValue | public double getDoubleColValue(String sql, String columnName) throws Throwable(Code) | | Execute query and return value of a given column
Parameters: sql - Query to execute and retrieve a recordset Parameters: columnName - Name of the column whose value will be retrieved Value of column as double throws: Throwable - if query fails or if recordset is empty |
getIntColValue | public int getIntColValue(String sql, String columnName) throws Throwable(Code) | | Execute query and return value of a given column
Parameters: sql - Query to execute and retrieve a recordset Parameters: columnName - Name of the column whose value will be retrieved Value of column as int throws: Throwable - if query fails or if recordset is empty |
saveBlob | public void saveBlob(String sql, String path) throws Throwable(Code) | | Save binary file to blob column using a prepared statement.
The prepared statement must contain only one dynamic parameter (?),
and it must correspond to the BLOB column. Example:
insert into images (id, title, imgsize, data) values (1,'my image', 8112, ?)
This means that the SQL must be pre-processed by your code in order to
set the static values. GenericTransaction superclass provides the method getSql()
to help you achieve easy static SQL generation.
Parameters: sql - SQL used to build prepared statement. The blob column will be the only dynamic (?) parameter. Parameters: path - File to be uploaded into the blob column throws: Throwable - |
setLogWriter | public void setLogWriter(PrintWriter writer)(Code) | | Set the log writer. This class will log
all query executions -as a text report- if this object is set
Parameters: writer - |
|
|