|
|||||||||
| Home >> All >> postgresql >> [ jdbc2 overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
postgresql.jdbc2
Class PreparedStatement

java.lang.Objectpostgresql.jdbc2.Statement
postgresql.jdbc2.PreparedStatement
- All Implemented Interfaces:
- java.sql.PreparedStatement, java.sql.Statement
- Direct Known Subclasses:
- CallableStatement
- public class PreparedStatement
- extends Statement
- implements java.sql.PreparedStatement
- extends Statement
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.sql.PreparedStatement |
getParameterMetaData, setURL |
| 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:
executeQueryin interfacejava.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:
executeUpdatein interfacejava.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:
setNullin interfacejava.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:
setBooleanin interfacejava.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:
setBytein interfacejava.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:
setShortin interfacejava.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:
setIntin interfacejava.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:
setLongin interfacejava.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:
setFloatin interfacejava.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:
setDoublein interfacejava.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:
setBigDecimalin interfacejava.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:
setStringin interfacejava.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:
setBytesin interfacejava.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:
setDatein interfacejava.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:
setTimein interfacejava.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:
setTimestampin interfacejava.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:
setAsciiStreamin interfacejava.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:
setUnicodeStreamin interfacejava.sql.PreparedStatement
- 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 **
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:
setBinaryStreamin interfacejava.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:
clearParametersin interfacejava.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:
setObjectin interfacejava.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
Objectvalue. The specified SQL object type will be used.- Specified by:
setObjectin interfacejava.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:
setObjectin interfacejava.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:
executein interfacejava.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:
addBatchin interfacejava.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:
getMetaDatain interfacejava.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
Arrayvalue. The default object type to SQL type mapping will be used.- Specified by:
setArrayin interfacejava.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
Blobvalue. The default object type to SQL type mapping will be used.- Specified by:
setBlobin interfacejava.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
Readervalue.- Specified by:
setCharacterStreamin interfacejava.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
Clobvalue. The default object type to SQL type mapping will be used.- Specified by:
setClobin interfacejava.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:
setNullin interfacejava.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
Refvalue. The default object type to SQL type mapping will be used.- Specified by:
setRefin interfacejava.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.Datevalue.- Specified by:
setDatein interfacejava.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.Timevalue.- Specified by:
setTimein interfacejava.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.Timestampvalue.- Specified by:
setTimestampin interfacejava.sql.PreparedStatement
|
|||||||||
| Home >> All >> postgresql >> [ jdbc2 overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC