Java Doc for PreparedStatement.java in  » Apache-Harmony-Java-SE » java-package » java » sql » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.sql 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.sql.PreparedStatement

PreparedStatement
public interface PreparedStatement extends Statement(Code)
An interface for a Precompiled SQL Statement.

An SQL Statement is put into a PreparedStatement and is precompiled so that it can be executed multiple times efficiently.

Setter methods are supplied in the PreparedStatement interface for the setting of IN parameters for the Statement. The setter method used for each IN parameter must match the type of the IN parameter being set.





Method Summary
public  voidaddBatch()
     Add a set of parameters to the PreparedStatement's command batch.
public  voidclearParameters()
     Clear the current parameter values.

Typically, parameter values are retained for multiple executions of the Statement.

public  booleanexecute()
     Executes the SQL statement in this PreparedStatement.

A PreparedStatement may return multiple results.

public  ResultSetexecuteQuery()
     Execute the SQL query in the PreparedStatement and return the ResultSet generated by the query.
public  intexecuteUpdate()
     Invoke the SQL command contained within the Prepared Statement.
public  ResultSetMetaDatagetMetaData()
     Returns a ResultSetMetaData containing data from the ResultSet that is produced when the PreparedStatement is invoked.

It is possible to know the Metadata for the ResultSet without executing the PreparedStatement, because the PreparedStatement is precompiled.

public  ParameterMetaDatagetParameterMetaData()
     Gets information about the parameters of the PreparedStatement.
public  voidsetArray(int parameterIndex, Array theArray)
     Sets the value of a specified parameter to the supplied Array object.
public  voidsetAsciiStream(int parameterIndex, InputStream theInputStream, int length)
     Sets the value of a specified parameter to the content of a supplied InputStream, which has a specified number of bytes.

This is a good method for setting an SQL LONVARCHAR parameter where the length of the data is large.

public  voidsetBigDecimal(int parameterIndex, BigDecimal theBigDecimal)
     Sets the value of a specified parameter to a supplied java.math.BigDecimal value.
public  voidsetBinaryStream(int parameterIndex, InputStream theInputStream, int length)
     Sets the value of a specified parameter to the content of a supplied binary InputStream, which has a specified number of bytes.
public  voidsetBlob(int parameterIndex, Blob theBlob)
     Sets the value of a specified parameter to the given Blob object.
public  voidsetBoolean(int parameterIndex, boolean theBoolean)
     Sets the value of a specified parameter to a supplied boolean value.
public  voidsetByte(int parameterIndex, byte theByte)
     Sets the value of a specified parameter to a supplied byte value.
public  voidsetBytes(int parameterIndex, byte[] theBytes)
     Sets the value of a specified parameter to a supplied array of bytes.
public  voidsetCharacterStream(int parameterIndex, Reader reader, int length)
     Sets the value of a specified parameter to the character content of a Reader object, with the specified length of character data.
public  voidsetClob(int parameterIndex, Clob theClob)
     Sets the value of a specified parameter to the given Clob object.
public  voidsetDate(int parameterIndex, Date theDate)
     Sets the value of a specified parameter to a supplied java.sql.Date value.
public  voidsetDate(int parameterIndex, Date theDate, Calendar cal)
     Sets the value of a specified parameter to a supplied java.sql.Date value, using a supplied Calendar to map the Date.
public  voidsetDouble(int parameterIndex, double theDouble)
     Sets the value of a specified parameter to a supplied double value.
public  voidsetFloat(int parameterIndex, float theFloat)
     Sets the value of a specified parameter to to a supplied float value.
public  voidsetInt(int parameterIndex, int theInt)
     Sets the value of a specified parameter to a supplied int value.
public  voidsetLong(int parameterIndex, long theLong)
     Sets the value of a specified parameter to a supplied long value.
public  voidsetNull(int parameterIndex, int sqlType)
     Sets the value of a specified parameter to SQL NULL.
public  voidsetNull(int paramIndex, int sqlType, String typeName)
     Sets the value of a specified parameter to SQL NULL.
public  voidsetObject(int parameterIndex, Object theObject)
     Sets the value of a specified parameter using a supplied object.

There is a standard mapping from Java types to SQL types, defined in the JDBC specification.

public  voidsetObject(int parameterIndex, Object theObject, int targetSqlType)
     Sets the value of a specified parameter.

The Object is converted to the target SQL type before it is added to the database.

public  voidsetObject(int parameterIndex, Object theObject, int targetSqlType, int scale)
     Sets the value of a specified parameter.

The Object is converted to the target SQL type before it is added to the database.

public  voidsetRef(int parameterIndex, Ref theRef)
     Sets the value of a specified parameter to a supplied REF() value.
public  voidsetShort(int parameterIndex, short theShort)
     Sets the value of a specified parameter to a supplied short value.
public  voidsetString(int parameterIndex, String theString)
     Sets the value of a specified parameter to a supplied String.
public  voidsetTime(int parameterIndex, Time theTime)
     Sets the value of a specified parameter to a supplied java.sql.Time value.
public  voidsetTime(int parameterIndex, Time theTime, Calendar cal)
     Sets the value of a specified parameter to a supplied java.sql.Time value, using a supplied Calendar.
public  voidsetTimestamp(int parameterIndex, Timestamp theTimestamp)
     Sets the value of a specified parameter to a supplied java.sql.Timestamp value.
public  voidsetTimestamp(int parameterIndex, Timestamp theTimestamp, Calendar cal)
     Sets the value of a specified parameter to a supplied java.sql.Timestamp value, using the supplied Calendar.
public  voidsetURL(int parameterIndex, URL theURL)
     Sets the value of a specified parameter to a supplied java.net.URL.
public  voidsetUnicodeStream(int parameterIndex, InputStream theInputStream, int length)
    



Method Detail
addBatch
public void addBatch() throws SQLException(Code)
Add a set of parameters to the PreparedStatement's command batch.
throws:
  SQLException - if a database error happens



clearParameters
public void clearParameters() throws SQLException(Code)
Clear the current parameter values.

Typically, parameter values are retained for multiple executions of the Statement. Setting a parameter value replaces the previous value. This method clears the values for all parameters, releasing all resources used by those parameters.
throws:
  SQLException - if a database error happens




execute
public boolean execute() throws SQLException(Code)
Executes the SQL statement in this PreparedStatement.

A PreparedStatement may return multiple results. The execute method returns a flag indicating the kind of result produced by PreparedStatement. The methods getResultSet or getUpdateCount are used to retrieve the first result, while getMoreResults must be used to retrieve the second and subsequent results. true if the result of the execution is a ResultSet, false ifthere is no result or if the result is an update count.
throws:
  SQLException - if a database error happens




executeQuery
public ResultSet executeQuery() throws SQLException(Code)
Execute the SQL query in the PreparedStatement and return the ResultSet generated by the query. the ResultSet generated by the query - never null.
throws:
  SQLException - if a database error happens or if the SQL statement does notproduce a ResultSet.



executeUpdate
public int executeUpdate() throws SQLException(Code)
Invoke the SQL command contained within the Prepared Statement. This must be INSERT, UPDATE, DELETE, or a command that returns nothing. the count of rows for INSERT, UPDATE or DELETE statements, 0 forstatements that return nothing
throws:
  SQLException - if a database error happens or if the SQL statement returns aResultSet.



getMetaData
public ResultSetMetaData getMetaData() throws SQLException(Code)
Returns a ResultSetMetaData containing data from the ResultSet that is produced when the PreparedStatement is invoked.

It is possible to know the Metadata for the ResultSet without executing the PreparedStatement, because the PreparedStatement is precompiled. As a result the Metadata can be queried ahead of time without actually executing the statement. a ResultSetMetaData object with the information about the columnsof the ResultSet, if the driver can return a ResultSetMetaData.null otherwise.
throws:
  SQLException - if there is a database error




getParameterMetaData
public ParameterMetaData getParameterMetaData() throws SQLException(Code)
Gets information about the parameters of the PreparedStatement. a ParameterMetaData object which holds information about thenumber, type and properties of the parameters of thisPreparedStatement.
throws:
  SQLException - if a database error happens



setArray
public void setArray(int parameterIndex, Array theArray) throws SQLException(Code)
Sets the value of a specified parameter to the supplied Array object.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theArray - a java.sql.Array holing the data to set.
throws:
  SQLException - if a database error happens



setAsciiStream
public void setAsciiStream(int parameterIndex, InputStream theInputStream, int length) throws SQLException(Code)
Sets the value of a specified parameter to the content of a supplied InputStream, which has a specified number of bytes.

This is a good method for setting an SQL LONVARCHAR parameter where the length of the data is large. Data is read from the InputStream until end-of-file is reached or the specified number of bytes is copied.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theInputStream - the ASCII InputStream carrying the data to update theparameter
Parameters:
  length - the number of bytes in the InputStream to copy to theparameter
throws:
  SQLException - if a database error happens




setBigDecimal
public void setBigDecimal(int parameterIndex, BigDecimal theBigDecimal) throws SQLException(Code)
Sets the value of a specified parameter to a supplied java.math.BigDecimal value.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theBigDecimal - the java.math.BigInteger value to set
throws:
  SQLException - if a database error happens



setBinaryStream
public void setBinaryStream(int parameterIndex, InputStream theInputStream, int length) throws SQLException(Code)
Sets the value of a specified parameter to the content of a supplied binary InputStream, which has a specified number of bytes.

Use this method when a large amount of data needs to be set into a LONGVARBINARY parameter.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theInputStream - the binary InputStream carrying the data to update theparameter
Parameters:
  length - the number of bytes in the InputStream to copy to theparameter
throws:
  SQLException - if a database error happens




setBlob
public void setBlob(int parameterIndex, Blob theBlob) throws SQLException(Code)
Sets the value of a specified parameter to the given Blob object.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theBlob - a java.sql.Blob holding the data to update the parameter
throws:
  SQLException - if a database error happens



setBoolean
public void setBoolean(int parameterIndex, boolean theBoolean) throws SQLException(Code)
Sets the value of a specified parameter to a supplied boolean value.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theBoolean - the boolean value to update the parameter
throws:
  SQLException - if a database error happens



setByte
public void setByte(int parameterIndex, byte theByte) throws SQLException(Code)
Sets the value of a specified parameter to a supplied byte value.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theByte - the byte value to update the parameter
throws:
  SQLException - if a database error happens



setBytes
public void setBytes(int parameterIndex, byte[] theBytes) throws SQLException(Code)
Sets the value of a specified parameter to a supplied array of bytes. The array is mapped to a VARBINARY or LONGVARBINARY in the database.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theBytes - the array of bytes to update the parameter
throws:
  SQLException - if a database error happens



setCharacterStream
public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException(Code)
Sets the value of a specified parameter to the character content of a Reader object, with the specified length of character data.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  reader - the java.io.Reader encompassing the character data
Parameters:
  length - the amount of characters to be read
throws:
  SQLException - if a database error happens



setClob
public void setClob(int parameterIndex, Clob theClob) throws SQLException(Code)
Sets the value of a specified parameter to the given Clob object.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theClob - a java.sql.Clob holding the data to update the parameter
throws:
  SQLException - if a database error happens



setDate
public void setDate(int parameterIndex, Date theDate) throws SQLException(Code)
Sets the value of a specified parameter to a supplied java.sql.Date value.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theDate - a java.sql.Date to update the parameter
throws:
  SQLException - if a database error happens



setDate
public void setDate(int parameterIndex, Date theDate, Calendar cal) throws SQLException(Code)
Sets the value of a specified parameter to a supplied java.sql.Date value, using a supplied Calendar to map the Date. The Calendar allows the application to control the timezone used to compute the SQL DATE in the database - without the supplied Calendar, the driver uses the default timezone of the Java virtual machine.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theDate - a java.sql.Date to update the parameter
Parameters:
  cal - a Calendar to use to construct the SQL DATE value
throws:
  SQLException - if a database error happens



setDouble
public void setDouble(int parameterIndex, double theDouble) throws SQLException(Code)
Sets the value of a specified parameter to a supplied double value.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theDouble - the double value to update the parameter
throws:
  SQLException - if a database error happens



setFloat
public void setFloat(int parameterIndex, float theFloat) throws SQLException(Code)
Sets the value of a specified parameter to to a supplied float value.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theFloat - the float value to update the parameter
throws:
  SQLException - if a database error happens



setInt
public void setInt(int parameterIndex, int theInt) throws SQLException(Code)
Sets the value of a specified parameter to a supplied int value.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theInt - the int value to update the parameter
throws:
  SQLException - if a database error happens



setLong
public void setLong(int parameterIndex, long theLong) throws SQLException(Code)
Sets the value of a specified parameter to a supplied long value.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theLong - the long value to update the parameter
throws:
  SQLException - if a database error happens



setNull
public void setNull(int parameterIndex, int sqlType) throws SQLException(Code)
Sets the value of a specified parameter to SQL NULL. Don't use this version of setNull for User Defined Types or for REF type parameters.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  sqlType - the SQL Type of the parameter, as defined in java.sql.Types
throws:
  SQLException - if a database error happens



setNull
public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException(Code)
Sets the value of a specified parameter to SQL NULL. This version of setNull should be used for User Defined Types (UDTs) and also REF types. UDTs can be STRUCT, DISTINCT, JAVA_OBJECT and named array types.

Applications must provide the SQL Type code and also a fully qualified SQL Type name when supplying a NULL UDT or REF. For a UDT, the type name is the type name of the parameter itself, but for a REF parameter the type name is the type name of the referenced type.
Parameters:
  paramIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  sqlType - the SQL Type of the parameter, as defined in java.sql.Types
Parameters:
  typeName - the fully qualified name of a UDT or REF type - ignored if theparameter is not a UDT.
throws:
  SQLException - if a database error happens




setObject
public void setObject(int parameterIndex, Object theObject) throws SQLException(Code)
Sets the value of a specified parameter using a supplied object.

There is a standard mapping from Java types to SQL types, defined in the JDBC specification. The passed object is then transformed into the appropriate SQL type, and then transferred to the database. setObject can be used to pass abstract data types unique to the database, by using a JDBC driver specific Java type. If the object's class implements the interface SQLData, the JDBC driver calls SQLData.writeSQL to write it to the SQL data stream. If the object's class implements Ref, Blob, Clob, Struct, or Array, the driver passes it to the database as a value of the corresponding SQL type.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theObject - the Object containing the value to update the parameter
throws:
  SQLException - if a database error happens




setObject
public void setObject(int parameterIndex, Object theObject, int targetSqlType) throws SQLException(Code)
Sets the value of a specified parameter.

The Object is converted to the target SQL type before it is added to the database. If the Object is an instance of SQLData then SQLData.writeSQL is called to write out its data.


Parameters:
  parameterIndex - the parameter index, where the first parameter has index 1
Parameters:
  theObject - the Object containing the value to update the parameter
Parameters:
  targetSqlType - the SQL Type to send to the database, as defined injava.sql.Types
throws:
  SQLException - if a database error happens



setObject
public void setObject(int parameterIndex, Object theObject, int targetSqlType, int scale) throws SQLException(Code)
Sets the value of a specified parameter.

The Object is converted to the target SQL type before it is added to the database. If the Object is an instance of SQLData then SQLData.writeSQL is called to write out its data.


Parameters:
  parameterIndex - the parameter index, where the first parameter has index 1
Parameters:
  theObject - the Object containing the value to update the parameter
Parameters:
  targetSqlType - the SQL Type to send to the database, as defined injava.sql.Types
Parameters:
  scale - the number of decimal places if the types isjava.sql.Types.DECIMAL or java.sql.Types.NUMERIC
throws:
  SQLException - if a database error happens



setRef
public void setRef(int parameterIndex, Ref theRef) throws SQLException(Code)
Sets the value of a specified parameter to a supplied REF() value. This is stored as an SQL REF.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theRef - a java.sql.Ref value to update the parameter
throws:
  SQLException - if a database error happens



setShort
public void setShort(int parameterIndex, short theShort) throws SQLException(Code)
Sets the value of a specified parameter to a supplied short value.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theShort - a short value to update the parameter
throws:
  SQLException - if a database error happens



setString
public void setString(int parameterIndex, String theString) throws SQLException(Code)
Sets the value of a specified parameter to a supplied String.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theString - a String value to update the parameter
throws:
  SQLException - if a database error happens



setTime
public void setTime(int parameterIndex, Time theTime) throws SQLException(Code)
Sets the value of a specified parameter to a supplied java.sql.Time value.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theTime - a java.sql.Time value to update the parameter
throws:
  SQLException - if a database error happens



setTime
public void setTime(int parameterIndex, Time theTime, Calendar cal) throws SQLException(Code)
Sets the value of a specified parameter to a supplied java.sql.Time value, using a supplied Calendar.

The driver uses the supplied Calendar to create the SQL TIME value, which allows it to use a custom timezone - otherwise the driver uses the default timezone of the Java virtual machine.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theTime - a java.sql.Time value to update the parameter
Parameters:
  cal - a Calendar to use to construct the SQL TIME value
throws:
  SQLException - if a database error happens




setTimestamp
public void setTimestamp(int parameterIndex, Timestamp theTimestamp) throws SQLException(Code)
Sets the value of a specified parameter to a supplied java.sql.Timestamp value.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theTimestamp - the java.sql.Timestamp value to update the parameter
throws:
  SQLException - if a database error happens



setTimestamp
public void setTimestamp(int parameterIndex, Timestamp theTimestamp, Calendar cal) throws SQLException(Code)
Sets the value of a specified parameter to a supplied java.sql.Timestamp value, using the supplied Calendar.

The driver uses the supplied Calendar to create the SQL TIMESTAMP value, which allows it to use a custom timezone - otherwise the driver uses the default timezone of the Java virtual machine.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theTimestamp - the java.sql.Timestamp value to update the parameter
Parameters:
  cal - a Calendar to use to construct the SQL TIMESTAMP value
throws:
  SQLException - if a database error happens




setURL
public void setURL(int parameterIndex, URL theURL) throws SQLException(Code)
Sets the value of a specified parameter to a supplied java.net.URL.
Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theURL - the URL to update the parameter
throws:
  SQLException - if a database error happens



setUnicodeStream
public void setUnicodeStream(int parameterIndex, InputStream theInputStream, int length) throws SQLException(Code)

Parameters:
  parameterIndex - the parameter number index, where the first parameter hasindex 1
Parameters:
  theInputStream - the InputStream with the character data to update theparameter
Parameters:
  length - the number of bytes to read from the InputStream
throws:
  SQLException - if a database error happens



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.