📄 jdbcpreparedstatement.java
字号:
if (read == -1) { break; } out.write(buff, 0, read); left -= read; } setParameter(parameterIndex, out.toByteArray()); } catch (IOException e) { throw Util.sqlException(Trace.INPUTSTREAM_ERROR, e.toString()); } finally { if (out != null) { try { out.close(); } catch (IOException e) {} } } } /** * <!-- 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 --> * * @exception SQLException if a database access error occurs */ public void clearParameters() throws SQLException { checkClosed(); ArrayUtil.fillArray(parameterValues, null); ArrayUtil.clearArray(ArrayUtil.CLASS_CODE_BOOLEAN, parameterSet, 0, parameterSet.length); if (parameterStream != null) { ArrayUtil.clearArray(ArrayUtil.CLASS_CODE_BOOLEAN, parameterStream, 0, parameterStream.length); } } //---------------------------------------------------------------------- // 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 --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Inculding 1.7.1,this method was identical to * {@link #setObject(int, Object, int) setObject(int, Object, int)}. * That is, this method simply called setObject(int, Object, int), * ignoring the scale specification. <p> * * Since 1.7.2, this method supports the conversions listed in the * conversion table B-5 of the JDBC 3 specification. The scale argument * is not used. * </div> * <!-- start release-specific documentation --> * * @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 * @see #setObject(int,Object,int) */ public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException { /** @todo fredt - implement SQLData support */ setObject(parameterIndex, x); } /** * <!-- 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 --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Since 1.7.2, this method supports conversions listed in the * conversion table B-5 of the JDBC 3 specification. * </div> * <!-- end release-specific documentation --> * * @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 * @see #setObject(int,Object) */ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { setObject(parameterIndex, x); } /** * <!-- 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 --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3><p> * * Since 1.7.2, this method supports conversions listed in the conversion * table B-5 of the JDBC 3 specification.<p> * * </div> * * @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 { setParameter(parameterIndex, x); } //--------------------------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 --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Since 1.7.2, this feature is supported. * </div> * <!-- 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) */// boucherb@users 20030801 - method implemented public void addBatch() throws SQLException { checkClosed(); int len = parameterValues.length; Object[] bpValues = new Object[len]; checkParametersSet(); System.arraycopy(parameterValues, 0, bpValues, 0, len); if (batchResultOut == null) { batchResultOut = new Result(ResultConstants.BATCHEXECUTE, parameterTypes, statementID); } batchResultOut.add(bpValues); } /** * <!-- 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 --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * HSQLDB stores CHARACTER and related SQL types as Unicode so * this method does not perform any conversion. * </div> * <!-- end release-specific documentation --> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param reader the <code>java.io.Reader</code> object that contains the * Unicode data * @param length the number of characters in the stream * @exception SQLException if a database access error occurs * @since JDK 1.2 (JDK 1.1.x developers: read the new overview for * jdbcPreparedStatement) */// fredt@users 20020429 - patch 1.7.0 - method defined// fredt@users 20020627 - patch 574234 by ohioedge@users// boucherb@users 20030801 - patch 1.7.2 - updated public void setCharacterStream(int parameterIndex, java.io.Reader reader, int length) throws SQLException { checkSetParameterIndex(parameterIndex, true); if (reader == null) { String msg = "reader is null"; throw Util.sqlException(Trace.INVALID_JDBC_ARGUMENT, msg); } final StringBuffer sb = new StringBuffer(); final int size = 2048; final char[] buff = new char[size]; try { for (int left = length; left > 0; ) { final int read = reader.read(buff, 0, left > size ? size : left); if (read == -1) { break; } sb.append(buff, 0, read); left -= read; } } catch (IOException e) { throw Util.sqlException(Trace.TRANSFER_CORRUPTED, e.toString()); } setParameter(parameterIndex, sb.toString()); } /** * <!-- start generic documentation --> * Sets the designated parameter to the given * <code>REF(<structured-type>)</code> value. * The driver converts this to an SQL <code>REF</code> value when it * sends it to the database. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * HSQLDB 1.7.2 does not support the SQL REF type. Calling this method * throws an exception. * * </div> * <!-- end release-specific documentation --> * @param i the first parameter is 1, the second is 2, ... * @param x an SQL <code>REF</code> value * @exception SQLException if a database access error occurs * @since JDK 1.2 (JDK 1.1.x developers: read the new overview for * jdbcPreparedStatement) */ public void setRef(int i, Ref x) throws SQLException { throw Util.notSupported(); } /** * <!-- start generic documentation --> * Sets the designated parameter to the given <code>Blob</code> object. * The driver converts this to an SQL <code>BLOB</code> value when it * sends it to the database. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -