Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

postgresql.jdbc2
Class PreparedStatement  view PreparedStatement download PreparedStatement.java

java.lang.Object
  extended bypostgresql.jdbc2.Statement
      extended bypostgresql.jdbc2.PreparedStatement
All Implemented Interfaces:
java.sql.PreparedStatement, java.sql.Statement
Direct Known Subclasses:
CallableStatement

public class PreparedStatement
extends Statement
implements java.sql.PreparedStatement

A SQL Statement is pre-compiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.

Note: The setXXX methods for setting IN parameter values must specify types that are compatible with the defined SQL type of the input parameter. For instance, if the IN parameter has SQL type Integer, then setInt should be used.

If arbitrary parameter type conversions are required, then the setObject method should be used with a target SQL type.


Field Summary
(package private)  Connection connection
           
(package private)  java.lang.String[] inStrings
           
(package private)  java.lang.String sql
           
(package private)  java.lang.String[] templateStrings
           
 
Fields inherited from class postgresql.jdbc2.Statement
escapeProcessing, result, timeout, warnings
 
Fields inherited from interface java.sql.Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO
 
Constructor Summary
PreparedStatement(Connection connection, java.lang.String sql)
          Constructor for the PreparedStatement class.
 
Method Summary
 void addBatch()
          This method adds a set of parameters to the batch for JDBC 2.0.
 void clearParameters()
          In general, parameter values remain in force for repeated used of a Statement.
 boolean execute()
          Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled by executeQuery and executeUpdate
 java.sql.ResultSet executeQuery()
          A Prepared SQL query is executed and its ResultSet is returned
 int executeUpdate()
          Execute a SQL INSERT, UPDATE or DELETE statement.
 java.sql.ResultSetMetaData getMetaData()
          This method returns meta data for the result set from this statement.
private  void set(int paramIndex, java.lang.String s)
          There are a lot of setXXX classes which all basically do the same thing.
 void setArray(int i, java.sql.Array x)
          This method sets the specified parameter from the given Java Array value.
 void setAsciiStream(int parameterIndex, java.io.InputStream x, int length)
          When a very large ASCII value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream.
 void setBigDecimal(int parameterIndex, java.math.BigDecimal x)
          Set a parameter to a java.lang.BigDecimal value.
 void setBinaryStream(int parameterIndex, java.io.InputStream x, int length)
          When a very large binary value is input to a LONGVARBINARY parameter, it may be more practical to send it via a java.io.InputStream.
 void setBlob(int i, java.sql.Blob x)
          This method sets the specified parameter from the given Java Blob value.
 void setBoolean(int parameterIndex, boolean x)
          Set a parameter to a Java boolean value.
 void setByte(int parameterIndex, byte x)
          Set a parameter to a Java byte value.
 void setBytes(int parameterIndex, byte[] x)
          Set a parameter to a Java array of bytes.
 void setCharacterStream(int i, java.io.Reader x, int length)
          This method sets the specified parameter from the given Java character Reader value.
 void setClob(int i, java.sql.Clob x)
          This method sets the specified parameter from the given Java Clob value.
 void setDate(int parameterIndex, java.sql.Date x)
          Set a parameter to a java.sql.Date value.
 void setDate(int i, java.sql.Date d, java.util.Calendar cal)
          This method sets the specified parameter from the given Java java.sql.Date value.
 void setDouble(int parameterIndex, double x)
          Set a parameter to a Java double value.
 void setFloat(int parameterIndex, float x)
          Set a parameter to a Java float value.
 void setInt(int parameterIndex, int x)
          Set a parameter to a Java int value.
 void setLong(int parameterIndex, long x)
          Set a parameter to a Java long value.
 void setNull(int parameterIndex, int sqlType)
          Set a parameter to SQL NULL
 void setNull(int i, int t, java.lang.String s)
          This method populates the specified parameter with a SQL NULL value for the specified type.
 void setObject(int parameterIndex, java.lang.Object x)
          This stores an Object into a parameter.
 void setObject(int parameterIndex, java.lang.Object x, int targetSqlType)
          This method sets the specified parameter from the given Java Object value.
 void setObject(int parameterIndex, java.lang.Object x, int targetSqlType, int scale)
          Set the value of a parameter using an object; use the java.lang equivalent objects for integral values.
 void setRef(int i, java.sql.Ref x)
          This method sets the specified parameter from the given Java Ref value.
 void setShort(int parameterIndex, short x)
          Set a parameter to a Java short value.
 void setString(int parameterIndex, java.lang.String x)
          Set a parameter to a Java String value.
 void setTime(int parameterIndex, java.sql.Time x)
          Set a parameter to a java.sql.Time value.
 void setTime(int i, java.sql.Time t, java.util.Calendar cal)
          This method sets the specified parameter from the given Java java.sql.Time value.
 void setTimestamp(int parameterIndex, java.sql.Timestamp x)
          Set a parameter to a java.sql.Timestamp value.
 void setTimestamp(int i, java.sql.Timestamp t, java.util.Calendar cal)
          This method sets the specified parameter from the given Java java.sql.Timestamp value.
 void setUnicodeStream(int parameterIndex, java.io.InputStream x, int length)
          Deprecated.  
 java.lang.String toString()
          Returns the SQL statement with the current template values substituted.
 
Methods inherited from class postgresql.jdbc2.Statement
addBatch, cancel, clearBatch, clearWarnings, close, execute, executeBatch, executeQuery, executeUpdate, getConnection, getFetchDirection, getFetchSize, getKeysetSize, getMaxFieldSize, getMaxRows, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetType, getResultStatusString, getUpdateCount, getWarnings, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setKeysetSize, setMaxFieldSize, setMaxRows, setQueryTimeout, setResultSetConcurrency, setResultSetType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.sql.PreparedStatement
getParameterMetaData, setURL
 
Methods inherited from interface java.sql.Statement
addBatch, cancel, clearBatch, clearWarnings, close, execute, execute, execute, execute, executeBatch, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setQueryTimeout
 

Field Detail

sql

java.lang.String sql

templateStrings

java.lang.String[] templateStrings

inStrings

java.lang.String[] inStrings

connection

Connection connection
Constructor Detail

PreparedStatement

public PreparedStatement(Connection connection,
                         java.lang.String sql)
                  throws java.sql.SQLException
Constructor for the PreparedStatement class. Split the SQL statement into segments - separated by the arguments. When we rebuild the thing with the arguments, we can substitute the args and join the whole thing together.

Method Detail

executeQuery

public java.sql.ResultSet executeQuery()
                                throws java.sql.SQLException
A Prepared SQL query is executed and its ResultSet is returned

Specified by:
executeQuery in interface java.sql.PreparedStatement

executeUpdate

public int executeUpdate()
                  throws java.sql.SQLException
Execute a SQL INSERT, UPDATE or DELETE statement. In addition, SQL statements that return nothing such as SQL DDL statements can be executed.

Specified by:
executeUpdate in interface java.sql.PreparedStatement

setNull

public void setNull(int parameterIndex,
                    int sqlType)
             throws java.sql.SQLException
Set a parameter to SQL NULL

Note: You must specify the parameters SQL type (although PostgreSQL ignores it)

Specified by:
setNull in interface java.sql.PreparedStatement

setBoolean

public void setBoolean(int parameterIndex,
                       boolean x)
                throws java.sql.SQLException
Set a parameter to a Java boolean value. The driver converts this to a SQL BIT value when it sends it to the database.

Specified by:
setBoolean in interface java.sql.PreparedStatement

setByte

public void setByte(int parameterIndex,
                    byte x)
             throws java.sql.SQLException
Set a parameter to a Java byte value. The driver converts this to a SQL TINYINT value when it sends it to the database.

Specified by:
setByte in interface java.sql.PreparedStatement

setShort

public void setShort(int parameterIndex,
                     short x)
              throws java.sql.SQLException
Set a parameter to a Java short value. The driver converts this to a SQL SMALLINT value when it sends it to the database.

Specified by:
setShort in interface java.sql.PreparedStatement

setInt

public void setInt(int parameterIndex,
                   int x)
            throws java.sql.SQLException
Set a parameter to a Java int value. The driver converts this to a SQL INTEGER value when it sends it to the database.

Specified by:
setInt in interface java.sql.PreparedStatement

setLong

public void setLong(int parameterIndex,
                    long x)
             throws java.sql.SQLException
Set a parameter to a Java long value. The driver converts this to a SQL BIGINT value when it sends it to the database.

Specified by:
setLong in interface java.sql.PreparedStatement

setFloat

public void setFloat(int parameterIndex,
                     float x)
              throws java.sql.SQLException
Set a parameter to a Java float value. The driver converts this to a SQL FLOAT value when it sends it to the database.

Specified by:
setFloat in interface java.sql.PreparedStatement

setDouble

public void setDouble(int parameterIndex,
                      double x)
               throws java.sql.SQLException
Set a parameter to a Java double value. The driver converts this to a SQL DOUBLE value when it sends it to the database

Specified by:
setDouble in interface java.sql.PreparedStatement

setBigDecimal

public void setBigDecimal(int parameterIndex,
                          java.math.BigDecimal x)
                   throws java.sql.SQLException
Set a parameter to a java.lang.BigDecimal value. The driver converts this to a SQL NUMERIC value when it sends it to the database.

Specified by:
setBigDecimal in interface java.sql.PreparedStatement

setString

public void setString(int parameterIndex,
                      java.lang.String x)
               throws java.sql.SQLException
Set a parameter to a Java String value. The driver converts this to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments size relative to the driver's limits on VARCHARs) when it sends it to the database.

Specified by:
setString in interface java.sql.PreparedStatement

setBytes

public void setBytes(int parameterIndex,
                     byte[] x)
              throws java.sql.SQLException
Set a parameter to a Java array of bytes. The driver converts this to a SQL VARBINARY or LONGVARBINARY (depending on the argument's size relative to the driver's limits on VARBINARYs) when it sends it to the database.

Implementation note:
With postgresql, this creates a large object, and stores the objects oid in this column.

Specified by:
setBytes in interface java.sql.PreparedStatement

setDate

public void setDate(int parameterIndex,
                    java.sql.Date x)
             throws java.sql.SQLException
Set a parameter to a java.sql.Date value. The driver converts this to a SQL DATE value when it sends it to the database.

Specified by:
setDate in interface java.sql.PreparedStatement

setTime

public void setTime(int parameterIndex,
                    java.sql.Time x)
             throws java.sql.SQLException
Set a parameter to a java.sql.Time value. The driver converts this to a SQL TIME value when it sends it to the database.

Specified by:
setTime in interface java.sql.PreparedStatement

setTimestamp

public void setTimestamp(int parameterIndex,
                         java.sql.Timestamp x)
                  throws java.sql.SQLException
Set a parameter to a java.sql.Timestamp value. The driver converts this to a SQL TIMESTAMP value when it sends it to the database.

Specified by:
setTimestamp in interface java.sql.PreparedStatement

setAsciiStream

public void setAsciiStream(int parameterIndex,
                           java.io.InputStream x,
                           int length)
                    throws java.sql.SQLException
When a very large ASCII value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream. JDBC will read the data from the stream as needed, until it reaches end-of-file. The JDBC driver will do any necessary conversion from ASCII to the database char format.

Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

Specified by:
setAsciiStream in interface java.sql.PreparedStatement

setUnicodeStream

public void setUnicodeStream(int parameterIndex,
                             java.io.InputStream x,
                             int length)
                      throws java.sql.SQLException
Deprecated.  

When a very large Unicode value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream. JDBC will read the data from the stream as needed, until it reaches end-of-file. The JDBC driver will do any necessary conversion from UNICODE to the database char format. ** DEPRECIATED IN JDBC 2 **

Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

Specified by:
setUnicodeStream in interface java.sql.PreparedStatement

setBinaryStream

public void setBinaryStream(int parameterIndex,
                            java.io.InputStream x,
                            int length)
                     throws java.sql.SQLException
When a very large binary value is input to a LONGVARBINARY parameter, it may be more practical to send it via a java.io.InputStream. JDBC will read the data from the stream as needed, until it reaches end-of-file.

Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

Specified by:
setBinaryStream in interface java.sql.PreparedStatement

clearParameters

public void clearParameters()
                     throws java.sql.SQLException
In general, parameter values remain in force for repeated used of a Statement. Setting a parameter value automatically clears its previous value. However, in coms cases, it is useful to immediately release the resources used by the current parameter values; this can be done by calling clearParameters

Specified by:
clearParameters in interface java.sql.PreparedStatement

setObject

public void setObject(int parameterIndex,
                      java.lang.Object x,
                      int targetSqlType,
                      int scale)
               throws java.sql.SQLException
Set the value of a parameter using an object; use the java.lang equivalent objects for integral values.

The given Java object will be converted to the targetSqlType before being sent to the database.

note that this method may be used to pass database-specific abstract data types. This is done by using a Driver-specific Java type and using a targetSqlType of java.sql.Types.OTHER

Specified by:
setObject in interface java.sql.PreparedStatement

setObject

public void setObject(int parameterIndex,
                      java.lang.Object x,
                      int targetSqlType)
               throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method sets the specified parameter from the given Java Object value. The specified SQL object type will be used.

Specified by:
setObject in interface java.sql.PreparedStatement

setObject

public void setObject(int parameterIndex,
                      java.lang.Object x)
               throws java.sql.SQLException
This stores an Object into a parameter.

New for 6.4, if the object is not recognised, but it is Serializable, then the object is serialised using the postgresql.util.Serialize class.

Specified by:
setObject in interface java.sql.PreparedStatement

execute

public boolean execute()
                throws java.sql.SQLException
Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled by executeQuery and executeUpdate

Specified by:
execute in interface java.sql.PreparedStatement

toString

public java.lang.String toString()
Returns the SQL statement with the current template values substituted.


set

private void set(int paramIndex,
                 java.lang.String s)
          throws java.sql.SQLException
There are a lot of setXXX classes which all basically do the same thing. We need a method which actually does the set for us.


addBatch

public void addBatch()
              throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method adds a set of parameters to the batch for JDBC 2.0.

Specified by:
addBatch in interface java.sql.PreparedStatement

getMetaData

public java.sql.ResultSetMetaData getMetaData()
                                       throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method returns meta data for the result set from this statement.

Specified by:
getMetaData in interface java.sql.PreparedStatement

setArray

public void setArray(int i,
                     java.sql.Array x)
              throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method sets the specified parameter from the given Java Array value. The default object type to SQL type mapping will be used.

Specified by:
setArray in interface java.sql.PreparedStatement

setBlob

public void setBlob(int i,
                    java.sql.Blob x)
             throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method sets the specified parameter from the given Java Blob value. The default object type to SQL type mapping will be used.

Specified by:
setBlob in interface java.sql.PreparedStatement

setCharacterStream

public void setCharacterStream(int i,
                               java.io.Reader x,
                               int length)
                        throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method sets the specified parameter from the given Java character Reader value.

Specified by:
setCharacterStream in interface java.sql.PreparedStatement

setClob

public void setClob(int i,
                    java.sql.Clob x)
             throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method sets the specified parameter from the given Java Clob value. The default object type to SQL type mapping will be used.

Specified by:
setClob in interface java.sql.PreparedStatement

setNull

public void setNull(int i,
                    int t,
                    java.lang.String s)
             throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method populates the specified parameter with a SQL NULL value for the specified type.

Specified by:
setNull in interface java.sql.PreparedStatement

setRef

public void setRef(int i,
                   java.sql.Ref x)
            throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method sets the specified parameter from the given Java Ref value. The default object type to SQL type mapping will be used.

Specified by:
setRef in interface java.sql.PreparedStatement

setDate

public void setDate(int i,
                    java.sql.Date d,
                    java.util.Calendar cal)
             throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method sets the specified parameter from the given Java java.sql.Date value.

Specified by:
setDate in interface java.sql.PreparedStatement

setTime

public void setTime(int i,
                    java.sql.Time t,
                    java.util.Calendar cal)
             throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method sets the specified parameter from the given Java java.sql.Time value.

Specified by:
setTime in interface java.sql.PreparedStatement

setTimestamp

public void setTimestamp(int i,
                         java.sql.Timestamp t,
                         java.util.Calendar cal)
                  throws java.sql.SQLException
Description copied from interface: java.sql.PreparedStatement
This method sets the specified parameter from the given Java java.sql.Timestamp value.

Specified by:
setTimestamp in interface java.sql.PreparedStatement