org.brains2b.sql.oracle.cursor
Class OracleCursor

java.lang.Object
  |
  +--org.brains2b.data.cursor.Cursor
        |
        +--org.brains2b.sql.oracle.cursor.OracleCursor

public class OracleCursor
extends Cursor

Overwrite of the Cursor object to add functionality for having queries with parameters.

The sql statement can contain placeholder characters ? signifying a parameter which can be set at runtime by calling addParameter(index, value). The index corresponds with the count of the placeholder character in the SQL statement starting at 1

Version:
0.21 [04-03-2004]
Author:
dennis@brains2b.nl

Field Summary
 
Fields inherited from class org.brains2b.data.cursor.Cursor
m_con, m_condition, m_from, m_groupBy, m_prep, m_select
 
Constructor Summary
OracleCursor()
          Deprecated. use OracleCursor(String, String) and OracleCursor(Connection,String,String)
OracleCursor(java.sql.Connection con, java.lang.String name, java.lang.String sql)
          Constructor for OracleCursor.
OracleCursor(java.lang.String name, java.lang.String sql)
          Constructor for OracleCursor
 
Method Summary
 void addParameter(int idx, int i)
          adds a integer value for the given placeholder position in the prepared statement.
 void addParameter(int idx, java.lang.Object o)
          adds a value for the given placeholder position in the prepared statement.
 int delete(CursorData cdata)
          Delete the data represented by the CursorData object from the database.
 java.sql.PreparedStatement getPreparedStatement(java.sql.Connection con, java.lang.String select)
          returns a prepared statement build from the prepared query set, the parameters added, the conditions set and the order by supplied.
 void reset()
          reset this Cursor by removing all previously set parameter values
 java.util.Vector select()
          Perform a select on the basis of the sql statement defined by this Cursor
 void setConnection(java.sql.Connection con)
          set the java.sql.Connection to use for this Cursor
 int update(CursorData cdata)
          Update the data represented by the CursorData object from the database.
 
Methods inherited from class org.brains2b.data.cursor.Cursor
getNewCursorData, getObject, getProtoType, select, select, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OracleCursor

public OracleCursor()
Deprecated. use OracleCursor(String, String) and OracleCursor(Connection,String,String)

Constructor for OracleCursor.


OracleCursor

public OracleCursor(java.lang.String name,
                    java.lang.String sql)
Constructor for OracleCursor

Parameters:
name - String, the name of the cursor
sql - String, the SQL-statement to use for this cursor

OracleCursor

public OracleCursor(java.sql.Connection con,
                    java.lang.String name,
                    java.lang.String sql)
Constructor for OracleCursor.

Usually the Connection does not have to be set at initialization, you can use setConnection(Connection)

Parameters:
con - java.sql.Connection, the JDBC connection to use for this Cursor
name - String, the name of the cursor
sql - String, the SQL-statement to use for this cursor
Method Detail

select

public java.util.Vector select()
                        throws java.lang.Exception
Description copied from class: Cursor
Perform a select on the basis of the sql statement defined by this Cursor

Overrides:
select in class Cursor
Returns:
java.util.Vector containing CursorData returned by the select statement
Throws:
java.lang.Exception - thrown if the database delivers an Exception

update

public int update(CursorData cdata)
           throws java.lang.Exception
Description copied from class: Cursor
Update the data represented by the CursorData object from the database.

Overrides:
update in class Cursor
Parameters:
cdata - CursorData, an object containing the results for the cursor
Returns:
int, the number of records affected by this update command, should always be 1
java.lang.Exception

delete

public int delete(CursorData cdata)
           throws java.lang.Exception
Description copied from class: Cursor
Delete the data represented by the CursorData object from the database.

Overrides:
delete in class Cursor
Parameters:
cdata - CursorData, an object containing the results for the cursor
Returns:
int, the number of records affected by this delete command, should always be 1
java.lang.Exception

addParameter

public void addParameter(int idx,
                         int i)
adds a integer value for the given placeholder position in the prepared statement.

Parameters:
idx - int, the placeholder position
i - int, The value to set in the prepared statement

addParameter

public void addParameter(int idx,
                         java.lang.Object o)
adds a value for the given placeholder position in the prepared statement.

Parameters:
idx - int, the placeholder position
o - Object, the value to set in the prepared statement.

reset

public void reset()
reset this Cursor by removing all previously set parameter values

See Also:
addParameter(int, int), addParameter(int, Object)

getPreparedStatement

public java.sql.PreparedStatement getPreparedStatement(java.sql.Connection con,
                                                       java.lang.String select)
                                                throws java.sql.SQLException
returns a prepared statement build from the prepared query set, the parameters added, the conditions set and the order by supplied.

If a prepared query has placeholders, the addParameters must be called for every placeholder supplied.

Parameters:
con - Connection, the connection for which to prepare the query
Returns:
PreparedStatement, the PreparedStatement created for execution
Throws:
SQLException, - throws the Exception if generated by the prepareStatement command in java.sql.Connection()
java.sql.SQLException
See Also:
java.sql.Connection(), PreparedStatement

setConnection

public void setConnection(java.sql.Connection con)
set the java.sql.Connection to use for this Cursor

Parameters:
con - java.sql.Connection