📄 jdbcpreparedstatement.java
字号:
* sends it to the database.<p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Since 1.7.1, HSQLDB handles Java positive/negative Infinity * and NaN <code>double</code> values consistent with the Java Language * Specification; these <em>special</em> values are now correctly stored * to and retrieved from the database. * </div> * <!-- start release-specific documentation --> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setDouble(int parameterIndex, double x) throws SQLException { Double d = new Double(x); setParameter(parameterIndex, d); } /** * <!-- start generic documentation --> * Sets the designated parameter to the given * <code>java.math.BigDecimal</code> value. * The driver converts this to an SQL <code>NUMERIC</code> value when * it sends it to the database.<p> * <!-- end generic documentation --> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { setParameter(parameterIndex, x); } /** * <!-- start generic documentation --> * Sets the designated parameter to the given Java <code>String</code> value. * The driver converts this * to an SQL <code>VARCHAR</code> or <code>LONGVARCHAR</code> value * (depending on the argument's * size relative to the driver's limits on <code>VARCHAR</code> values) * when it sends it to the database.<p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Including 1.7.2, HSQLDB stores all XXXCHAR values as java.lang.String * objects; there is no appreciable difference between * CHAR, VARCHAR and LONGVARCHAR. * </div> * <!-- start release-specific documentation --> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setString(int parameterIndex, String x) throws SQLException { setParameter(parameterIndex, x); } /** * <!-- start generic documentation --> * Sets the designated parameter to the given Java array of bytes. * The driver converts this to an SQL <code>VARBINARY</code> or * <code>LONGVARBINARY</code> (depending on the argument's size relative * to the driver's limits on <code>VARBINARY</code> values) when it * sends it to the database.<p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Including 1.7.2, HSQLDB stores all XXXBINARY values the same way; there * is no appreciable difference between BINARY, VARBINARY and * LONGVARBINARY. * </div> * <!-- start release-specific documentation --> * * @param paramIndex the first parameter is 1, the second is 2, ... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setBytes(int paramIndex, byte[] x) throws SQLException { setParameter(paramIndex, x); } /** * <!-- start generic documentation --> * Sets the designated parameter to the given * <code>java.sql.Date</code> value. The driver converts this * to an SQL <code>DATE</code> value when it sends it to the database.<p> * <!-- end generic documentation --> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setDate(int parameterIndex, Date x) throws SQLException { setParameter(parameterIndex, x); } /** * <!-- start generic documentation --> * Sets the designated parameter to the given <code>java.sql.Time</code> * value. The driver converts this to an SQL <code>TIME</code> value when it * sends it to the database.<p> * <!-- end generic documentation --> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setTime(int parameterIndex, Time x) throws SQLException { setParameter(parameterIndex, x); } /** * <!-- start generic documentation --> * Sets the designated parameter to the given * <code>java.sql.Timestamp</code> value. The driver converts this to * an SQL <code>TIMESTAMP</code> value when it sends it to the * database.<p> * <!-- end generic documentation --> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { setParameter(parameterIndex, x); } /** * <!-- start generic documentation --> * Sets the designated parameter to the given input stream, which will have * the specified number of bytes. * When a very large ASCII value is input to a <code>LONGVARCHAR</code> * parameter, it may be more practical to send it via a * <code>java.io.InputStream</code>. Data will be read from the stream * as needed until end-of-file is reached. The JDBC driver will * do any necessary conversion from ASCII 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> * * This method uses the default platform character encoding to convert bytes * from the stream into the characters of a String. In the future this is * likely to change to always treat the stream as ASCII.<p> * * Before HSQLDB 1.7.0, <code>setAsciiStream</code> and * <code>setUnicodeStream</code> were identical. * </div> * <!-- end release-specific documentation --> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x the Java input stream that contains the ASCII parameter value * @param length the number of bytes in the stream * @exception SQLException if a database access error occurs */ public void setAsciiStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException { checkSetParameterIndex(parameterIndex, true); String s; if (x == null) { s = "input stream is null"; throw Util.sqlException(Trace.INVALID_JDBC_ARGUMENT, s); } try { s = StringConverter.inputStreamToString(x, length); setParameter(parameterIndex, s); } catch (IOException e) { throw Util.sqlException(Trace.INVALID_CHARACTER_ENCODING); } } /** * <!-- start generic documentation --> * Sets the designated parameter to the given input stream, which * will have the specified number of bytes. A Unicode character has * two bytes, with the first byte being the high byte, and the second * being the low byte. * * 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.InputStream</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> * * Since 1.7.0, this method complies with behavior as defined by the * JDBC3 specification. * </div> * <!-- end release-specific documentation --> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x a <code>java.io.InputStream</code> object that contains the * Unicode parameter value as two-byte Unicode characters * @param length the number of bytes in the stream * @exception SQLException if a database access error occurs * @deprecated Sun does not include a reason, but presumably * this is because setCharacterStream is now prefered *///#ifdef DEPRECATEDJDBC public void setUnicodeStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException { checkSetParameterIndex(parameterIndex, true); String msg = null; if (x == null) { msg = "input stream is null"; } else if (length % 2 != 0) { msg = "odd length argument"; } if (msg != null) { throw Util.sqlException(Trace.INVALID_JDBC_ARGUMENT, msg); } int chlen = length / 2; int chread = 0; StringBuffer sb = new StringBuffer(); int hi; int lo; try { for (; chread < chlen; chread++) { hi = x.read(); if (hi == -1) { break; } lo = x.read(); if (lo == -1) { break; } sb.append((char) (hi << 8 | lo)); } } catch (IOException e) { throw Util.sqlException(Trace.TRANSFER_CORRUPTED); } setParameter(parameterIndex, sb.toString()); }//#endif /** * <!-- start generic documentation --> * Sets the designated parameter to the given input stream, which will have * the specified number of bytes. * When a very large binary value is input to a <code>LONGVARBINARY</code> * parameter, it may be more practical to send it via a * <code>java.io.InputStream</code> object. The data will be read from the * stream as needed until end-of-file is reached. * * <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> * * Since 1.7.2, this method works according to the standard. * </div> * <!-- end release-specific documentation --> * * @param parameterIndex the first parameter is 1, the second is 2, ... * @param x the java input stream which contains the binary parameter value * @param length the number of bytes in the stream * @exception SQLException if a database access error occurs */ public void setBinaryStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException { checkSetParameterIndex(parameterIndex, true); if (x == null) { throw Util.sqlException(Trace.error(Trace.INVALID_JDBC_ARGUMENT, Trace.JDBC_NULL_STREAM)); } HsqlByteArrayOutputStream out = null; try { out = new HsqlByteArrayOutputStream(); int size = 2048; byte[] buff = new byte[size]; for (int left = length; left > 0; ) { int read = x.read(buff, 0, left > size ? size : left);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -