com.ora.jsp.beans.sql
Class SQLCommandBean

java.lang.Object
  extended bycom.ora.jsp.beans.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 an SQL statement with question marks as placeholders for the value objects in the values property.

Version:
2.0
Author:
Hans Bergsten, Gefion software

Field Summary
private  java.sql.Connection conn
           
private  java.lang.String sqlValue
           
private  java.util.List values
           
 
Constructor Summary
SQLCommandBean()
           
 
Method Summary
 javax.servlet.jsp.jstl.sql.Result executeQuery()
          Executes the specified SQL string as a query and returns a Result object
 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 question mark placeholders for values set by setValues().
 void setValues(java.util.List values)
          Sets the values to use for the place holders in the SQL string.
private  void setValues(java.sql.PreparedStatement pstmt, java.util.List values)
          Calls setObject() method on the PreparedStatement for all objects in the values List.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conn

private java.sql.Connection conn

sqlValue

private java.lang.String sqlValue

values

private java.util.List values
Constructor Detail

SQLCommandBean

public SQLCommandBean()
Method Detail

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 question mark placeholders for values set by setValues().


setValues

public void setValues(java.util.List values)
Sets the values to use for the place holders in the SQL string. The List must contain one Object for each place holder, suitable for use with the PreparedStatement setObject() method.


executeQuery

public javax.servlet.jsp.jstl.sql.Result executeQuery()
                                               throws java.sql.SQLException
Executes the specified SQL string as a query and returns a Result object

Returns:
a javax.servlet.jsp.jstl.sql.Result object
Throws:
java.sql.SQLException

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.List values)
                throws java.sql.SQLException
Calls setObject() method on the PreparedStatement for all objects in the values List.

Parameters:
pstmt - the PreparedStatement
values - a List with objects
Throws:
java.sql.SQLException