📄 jdbcpreparedstatement.java
字号:
try { x.read(b, 0, length); x.close(); } catch (IOException e) { throw Trace.error(Trace.INPUTSTREAM_ERROR, e.getMessage()); } setBytes(parameterIndex, b); } /** * <!-- start generic documentation --> * Clears the current parameter values immediately. <p> * * In general, parameter values remain in force for repeated use of a * statement. Setting a parameter value automatically clears its * previous value. However, in some cases it is useful to immediately * release the resources used by the current parameter values; this can * be done by calling the method <code>clearParameters</code>.<p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * * @exception SQLException if a database access error occurs */ public void clearParameters() throws SQLException { if (Trace.TRACE) { Trace.trace(); } vParameter.removeAllElements(); } //---------------------------------------------------------------------- // Advanced features: /** * <!-- start generic documentation --> * Sets the value of the designated parameter with the given object. <p> * * The second argument must be an object type; for integral values, the * <code>java.lang</code> equivalent objects should be used. <p> * * The given Java object will be converted to the given targetSqlType * before being sent to the database. * * If the object has a custom mapping (is of a class implementing the * interface <code>SQLData</code>), * the JDBC driver should call the method <code>SQLData.writeSQL</code> to * write it to the SQL data stream. * If, on the other hand, the object is of a class implementing * <code>Ref</code>, <code>Blob</code>, <code>Clob</code>, * <code>Struct</code>, or <code>Array</code>, the driver should pass it * to the database as a value of the corresponding SQL type. <p> * * Note that this method may be used to pass database-specific * abstract data types.<p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b> <p> * * Up to and including HSQLDB 1.7.0, calling this method is identical to * calling * {@link #setObject(int, Object, int) setObject(int, Object, int)}. * That is, this method simply calls setObject(int, Object, int), * ignoring the scale specification. * </span> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x the object containing the input parameter value * @param targetSqlType the SQL type (as defined in java.sql.Types) to be * sent to the database. The scale argument may further qualify this type. * @param scale for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types, * this is the number of digits after the decimal point. For all * other types, this value will be ignored. <p> * * Up to and including HSQLDB 1.7.0, this parameter is ignored. * @exception SQLException if a database access error occurs * @see java.sql.Types */ public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException { if (Trace.TRACE) { Trace.trace(); } setObject(parameterIndex, x, targetSqlType); } /** * <!-- start generic documentation --> * Sets the value of the designated parameter with the given object. * This method is like the method <code>setObject</code> * above, except that it assumes a scale of zero. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b> <p> * * Up to HSQLDB 1.6.1, this method did not work properly with all * combinations of object class and targetSqlType. <p> * * Starting with 1.7.0, this has been corrected. <p> * * </span> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x the object containing the input parameter value * @param targetSqlType the SQL type (as defined in java.sql.Types) to be * sent to the database * @exception SQLException if a database access error occurs */ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { if (Trace.TRACE) { Trace.trace(); } if (x == null) { setNull(parameterIndex); return; }// fredt@users 20020328 - patch 482109 by fredt - OBJECT handling if (targetSqlType != Types.OTHER) { x = Column.convertObject(x, targetSqlType); } setObjectInType(parameterIndex, x, targetSqlType); } /** * <!-- start generic documentation --> * Sets the value of the designated parameter using the given object. <p> * * The second parameter must be of type <code>Object</code>; therefore, * the <code>java.lang</code> equivalent objects should be used for * built-in types. <p> * * The JDBC specification specifies a standard mapping from * Java <code>Object</code> types to SQL types. The given argument * will be converted to the corresponding SQL type before being * sent to the database. <p> * * Note that this method may be used to pass datatabase- * specific abstract data types, by using a driver-specific Java * type. If the object is of a class implementing the interface * <code>SQLData</code>, the JDBC driver should call the method * <code>SQLData.writeSQL</code> to write it to the SQL data stream. * If, on the other hand, the object is of a class implementing * <code>Ref</code>, <code>Blob</code>, <code>Clob</code>, * <code>Struct</code>, or <code>Array</code>, the driver should pass * it to the database as a value of the corresponding SQL type. <p> * * This method throws an exception if there is an ambiguity, for * example, if the object is of a class implementing more than one * of the interfaces named above.<p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b><p> * * This method will call the apropriate setXXX method when it detects that * the specified Object is one that has a standard mapping to a * java.sql.Types type. However, if it known that the parameter will * correspond to a value for (or comparison against) a column of type * OTHER, then the method <code>setObject(i,x,Types.OTHER)</code> * should be used instead; in HSQLDB, columns of type OTHER are * reserved strictly for storing serialized Java Objects. That is, * when attempting to insert or update using values other than * null for OTHER column values, an exception is thrown if the value * is not a serializable Java Object. <p> * * </span> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x the object containing the input parameter value * @exception SQLException if a database access error occurs or the type * of the given object is ambiguous */ public void setObject(int parameterIndex, Object x) throws SQLException { if (Trace.TRACE) { Trace.trace(); } if (x == null) { setNull(parameterIndex); return; } int type = Types.OTHER; if (x instanceof String) { type = Types.VARCHAR; } else if (x instanceof BigDecimal) { type = Types.NUMERIC; } else if (x instanceof Integer) { type = Types.INTEGER; } else if (x instanceof Long) { type = Types.BIGINT; } else if (x instanceof Float) { type = Types.REAL; } else if (x instanceof Double) { type = Types.DOUBLE; } else if (x instanceof byte[]) { type = Types.BINARY; } else if (x instanceof java.sql.Date) { type = Types.DATE; } else if (x instanceof Time) { type = Types.TIME; } else if (x instanceof Timestamp) { type = Types.TIMESTAMP; } else if (x instanceof Boolean) { type = Types.BIT; } else if (x instanceof Byte) { type = Types.TINYINT; } else if (x instanceof Short) { type = Types.SMALLINT; } setObjectInType(parameterIndex, x, type); } /** * <!-- start generic documentation --> * Executes the SQL statement in this <code>PreparedStatement</code> * object, which may be any kind of SQL statement. * Some prepared statements return multiple results; the * <code>execute</code> method handles these complex statements as well * as the simpler form of statements handled by the methods * <code>executeQuery</code>and <code>executeUpdate</code>. <p> * * The <code>execute</code> method returns a <code>boolean</code> to * indicate the form of the first result. You must call either the method * <code>getResultSet</code> or <code>getUpdateCount</code> * to retrieve the result; you must call <code>getMoreResults</code> to * move to any subsequent result(s). <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b> <p> * * Up to and including HSQLDB 1.7.0, statements never return multiple * result sets. However, be aware that this behaviour <i>may</i> * change in a future release. * </span> * * @return <code>true</code> if the first result is a <code>ResultSet</code> * object; <code>false</code> if the first result is an update * count or there is no result * @exception SQLException if a database access error occurs or an argument * is supplied to this method * @see jdbcStatement#execute * @see jdbcStatement#getResultSet * @see jdbcStatement#getUpdateCount * @see jdbcStatement#getMoreResults */ public boolean execute() throws SQLException { if (Trace.TRACE) { Trace.trace(); } return super.execute(build()); } //--------------------------JDBC 2.0----------------------------- /** * <!-- start generic documentation --> * Adds a set of parameters to this <code>PreparedStatement</code> * object's batch of commands. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <B>HSQLDB-Specific Information:</B> <p> * * HSQLDB 1.7.1 does not support this feature. <p> * * Calling this method always throws a <CODE>SQLException</CODE>, * stating that the function is not supported. <p> * * </span> * <!-- end release-specific documentation --> * * @exception SQLException if a database access error occurs * @see jdbcStatement#addBatch * @since JDK 1.2 (JDK 1.1.x developers: read the new overview for * jdbcPreparedStatement) */ public void addBatch() throws SQLException { throw getNotSupported(); } /** * <!-- start generic documentation --> * Sets the designated parameter to the given <code>Reader</code> * object, which is the given number of characters long. * When a very large UNICODE value is input to a <code>LONGVARCHAR</code> * parameter, it may be more practical to send it via a * <code>java.io.Reader</code> object. The data will be read from the * stream as needed until end-of-file is reached. The JDBC driver will * do any necessary conversion from UNICODE to the database char format. * * <P><B>Note:</B> This stream object can either be a standard * Java stream object or your own subclass that implements the * standard interface. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <B>HSQLDB-Specific Information:</B> <p> * * HSQLDB 1.7.0 stores CHARACTER and related SQL types as Unicode so * this method does not perform any conversion.<p> * * </span> * <!-- end release-specific documentation --> * * @param parameterIndex the first parameter is 1, the second is 2, ...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -