com.ora.jsp.sql
Class SQLCommandBean
java.lang.Object
|
+--com.ora.jsp.sql.SQLCommandBean
- public class SQLCommandBean
- extends java.lang.Object
This class is a bean for executing SQL statements. It has three
properties that can be set: connection, sqlValue and values.
The connection and sqlValue properties must always be set before
calling one of the execute methods. If the values property is
set, the sqlValue property must be a SQL statement with question
marks as placeholders for the Value objects in the values
property.
- Version:
- 1.0
- Author:
- Hans Bergsten, Gefion software
Method Summary |
java.util.Vector |
executeQuery()
Executes the specified SQL string as a query and returns
a Vector with Row objects, or an empty Vector if no rows
where found. |
int |
executeUpdate()
Executes the specified SQL string (any statement except SELECT, such
as UPDATE, INSERT, DELETE or CREATE TABLE) and returns
the number of rows affected by the statement, or 0 if none. |
void |
setConnection(java.sql.Connection conn)
Sets the Connection to use. |
void |
setSqlValue(java.lang.String sqlValue)
Set the SQL string, possibly with ? place holders for
values set by setValues(). |
private void |
setValues(java.sql.PreparedStatement pstmt,
java.util.Vector values)
Calls setXXX() methods on the PreparedStatement for all Value
objects in the values Vector. |
void |
setValues(java.util.Vector values)
Sets the values to use for the place holders in the SQL
string. |
private java.util.Vector |
toVector(java.sql.ResultSet rs)
Gets all data from the ResultSet and returns it as a Vector,
of Row objects. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
conn
private java.sql.Connection conn
sqlValue
private java.lang.String sqlValue
values
private java.util.Vector values
isExceptionThrown
private boolean isExceptionThrown
SQLCommandBean
public SQLCommandBean()
setConnection
public void setConnection(java.sql.Connection conn)
- Sets the Connection to use.
setSqlValue
public void setSqlValue(java.lang.String sqlValue)
- Set the SQL string, possibly with ? place holders for
values set by setValues().
setValues
public void setValues(java.util.Vector values)
- Sets the values to use for the place holders in the SQL
string. The Vector must contain one Value object for
each place holder.
executeQuery
public java.util.Vector executeQuery()
throws java.sql.SQLException,
UnsupportedTypeException
- Executes the specified SQL string as a query and returns
a Vector with Row objects, or an empty Vector if no rows
where found.
- Returns:
- a Vector of Row objects
- Throws:
java.sql.SQLException
- UnsupportedTypeException,
- if the returned value
doesn't match any Value subclass
executeUpdate
public int executeUpdate()
throws java.sql.SQLException
- Executes the specified SQL string (any statement except SELECT, such
as UPDATE, INSERT, DELETE or CREATE TABLE) and returns
the number of rows affected by the statement, or 0 if none.
- Returns:
- the number of rows affected
- Throws:
java.sql.SQLException
-
setValues
private void setValues(java.sql.PreparedStatement pstmt,
java.util.Vector values)
throws java.sql.SQLException
- Calls setXXX() methods on the PreparedStatement for all Value
objects in the values Vector.
- Parameters:
pstmt
- the PreparedStatementvalues
- a Vector with Value objects- Throws:
java.sql.SQLException
-
toVector
private java.util.Vector toVector(java.sql.ResultSet rs)
throws java.sql.SQLException,
UnsupportedTypeException
- Gets all data from the ResultSet and returns it as a Vector,
of Row objects.
- Parameters:
rs
- the ResultSet- Returns:
- a Vector of Row objects
- Throws:
SQLException,
- thrown by the JDBC API callsUnsupportedTypeException,
- if the returned value
doesn't match any Value subclass