2004.04.29


com.jdc.rdb.sql.dml.insert
Class Insert

java.lang.Object
  |
  +--com.jdc.lang.Object
        |
        +--com.jdc.rdb.sql.SQL
              |
              +--com.jdc.rdb.sql.dml.DML
                    |
                    +--com.jdc.rdb.sql.dml.insert.Insert
All Implemented Interfaces:
Serializable, Statement

public class Insert
extends DML

Insert represents a Data Manipulation Language Insert SQL statement. The Insert statement inserts a row into a database Table or View. Inserting a row into a View also inserts the row into the Table on which the View is based.

Invocation:
This statement can be embedded in an application program or issued through the use of dynamic SQL statements. It is an executable statement that can be dynamically prepared.
Authorization:
To execute this statement, the privileges held by the authorization ID of the statement must include at least one of the following (for IBM® DB2 Universal Database™):
Example:
        Insert insert = new Insert(table);

        insert.setValue(column 1 , true      );  // boolean Column
        insert.setValue(column 2 , 123       );  // int Column
        insert.setValue(column 3 , "String"  );  // String Column
        insert.setValue(column 4 , new Date());  // Date Column
        . . .

        InsertStatus status = insert.execute();
 
        if (status.isSuccessful())
        {
            // Insert success
        }
        else
        {
            // Insert failed!
        }
Reference:
IBM® DB2 Universal Database™ SQL Reference Volume 2 Version 8, Pages 603 thru 612.
Note:
Insert into a View is not currently supported.

Version:
2.0
Author:
Jay Damon
See Also:
Into, Columns, Values, With, Serialized Form

Field Summary
static String COMMAND
          The Insert statement command keyword.
 
Fields inherited from class com.jdc.rdb.sql.dml.DML
sql
 
Fields inherited from class com.jdc.lang.Object
string
 
Constructor Summary
Insert()
          Constructs a new Insert statement object.
Insert(String statement)
          Constructs a new Insert statement object for the specified Insert statement.
Insert(Table table)
          Constructs a new Insert statement object for the specified Database Table.
 
Method Summary
 InsertStatus execute()
          Executes the Insert statement and returns an InsertStatus object.
 Columns getColumns()
          Returns the Columns clause for this Insert statement.
 Into getInto()
          Returns the Into clause for this Insert statement.
 Values getValues()
          Returns the Values clause for this Insert statement.
protected  boolean isValid()
          Returns true if the Insert statement is valid.
 Insert set(InsertClause clause)
          Sets an InsertClause for this Insert statement.
 Insert setValue(Column column, boolean value)
          Sets a boolean value for the specified Column.
 Insert setValue(Column column, int value)
          Sets an int value for the specified Column.
 Insert setValue(Column column, Object value)
          Sets an Object value for the specified Column.
 
Methods inherited from class com.jdc.rdb.sql.dml.DML
finalize, getColumn, getConnection, getTable, setTable
 
Methods inherited from class com.jdc.rdb.sql.SQL
addClause, execute, getClause, getCommand, getStatement, setCommand, setConnection, setStatement, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COMMAND

public static final String COMMAND
The Insert statement command keyword.

See Also:
Constant Field Values
Constructor Detail

Insert

public Insert()
Constructs a new Insert statement object.


Insert

public Insert(Table table)
Constructs a new Insert statement object for the specified Database Table.

Throws:
SQLInvalidException - No table definition is specified.

Insert

public Insert(String statement)
Constructs a new Insert statement object for the specified Insert statement.

Throws:
SQLInvalidException - No INSERT statement is specified.
Method Detail

execute

public InsertStatus execute()
Executes the Insert statement and returns an InsertStatus object.

Returns:
The Insert statement status.

getColumns

public Columns getColumns()
Returns the Columns clause for this Insert statement.

Returns:
The Insert statement Columns clause.

getInto

public Into getInto()
Returns the Into clause for this Insert statement.

Returns:
The Insert statement Into clause.

getValues

public Values getValues()
Returns the Values clause for this Insert statement.

Returns:
The Insert statement Values clause.

isValid

protected boolean isValid()
Returns true if the Insert statement is valid.

Overrides:
isValid in class SQL
Returns:
This method always returns true.

set

public Insert set(InsertClause clause)
Sets an InsertClause for this Insert statement. Use this method to specify a custom Insert clause.

Returns:
This Insert statement object.
Throws:
SQLInvalidException - No INSERT statement clause is specified.

setValue

public Insert setValue(Column column,
                       boolean value)
Sets a boolean value for the specified Column. The Column alias is used to create the Columns clause and the boolean value is used to create the Values clause for this Insert statement.

Returns:
This Insert statement object.
Throws:
SQLInvalidException - No column is specified, an invalid column is specified, or a column for which a value has already been set is specified.

setValue

public Insert setValue(Column column,
                       int value)
Sets an int value for the specified Column. The Column alias is used to create the Columns clause and the int value is used to create the Values clause for this Insert statement.

Returns:
This Insert statement object.
Throws:
SQLInvalidException - No column is specified, an invalid column is specified, or a column for which a value has already been set is specified.

setValue

public Insert setValue(Column column,
                       Object value)
Sets an Object value for the specified Column. The Column alias is used to create the Columns clause and the Object value is used to create the Values clause for this Insert statement.

Returns:
This Insert statement object.
Throws:
SQLInvalidException - No column is specified, an invalid column is specified, or a column for which a value has already been set is specified.

2004.04.29



Copyright © 2004 J. Damon & Co.; All Rights Reserved WorldWide.