⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdbcpreparedstatement.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *     * Previous to 1.7.2, this feature was not supported. <p>     *     * Since 1.7.2, setBlob is supported.  With 1.7.2, setting Blob objects is     * limited to those of length less than or equal to Integer.MAX_VALUE.     * In 1.7.2, setBlob(i,x) is roughly equivalent (null and length handling     * not shown) to:     *     * <pre class="JavaCodeExample">     * <b>setBinaryStream</b>(i, x.<b>getBinaryStream</b>(), (<span class="JavaKeyWord">int</span>) x.<b>length</b>());     * </pre></div>     * <!-- end release-specific documentation -->     *     * @param i the first parameter is 1, the second is 2, ...     * @param x a <code>Blob</code> object that maps an SQL <code>BLOB</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)     */// boucherb@users 20030801 - method implemented//#ifdef JAVA2    public void setBlob(int i, Blob x) throws SQLException {        if (x instanceof jdbcBlob) {            setParameter(i, ((jdbcBlob) x).data);            return;        } else if (x == null) {            setParameter(i, null);            return;        }        checkSetParameterIndex(i, false);        final long length = x.length();        if (length > Integer.MAX_VALUE) {            String msg = "Maximum Blob input octet length exceeded: "                         + length;            throw Util.sqlException(Trace.INPUTSTREAM_ERROR, msg);        }        HsqlByteArrayOutputStream out = null;        try {            out = new HsqlByteArrayOutputStream();            java.io.InputStream in       = x.getBinaryStream();            int                 buffSize = 2048;            byte[]              buff     = new byte[buffSize];            for (int left = (int) length; left > 0; ) {                int read = in.read(buff, 0, left > buffSize ? buffSize                                                            : left);                if (read == -1) {                    break;                }                out.write(buff, 0, read);                left -= read;            }            setParameter(i, out.toByteArray());        } catch (IOException e) {            throw Util.sqlException(Trace.INPUTSTREAM_ERROR, e.toString());        } finally {            if (out != null) {                try {                    out.close();                } catch (IOException e) {}            }        }    }//#endif JAVA2    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given <code>Clob</code> object.     * The driver converts this to an SQL <code>CLOB</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>     *     * Previous to 1.7.2, this feature was not supported. <p>     *     * Since 1.7.2, setClob is supported.  With 1.7.2, setting Blob objects is     * limited to those of length less than or equal to Integer.MAX_VALUE.     * In 1.7.2, setClob(i,x) is rougly equivalent (null and length handling     * not shown) to: <p>     *     * <pre class="JavaCodeExample">     * <b>setCharacterStream</b>(i, x.<b>getCharacterStream</b>(), (<span class="JavaKeyWord">int</span>) x.<b>length</b>());     * </pre></div>     * <!-- end release-specific documentation -->     * @param i the first parameter is 1, the second is 2, ...     * @param x a <code>Clob</code> object that maps an SQL <code>CLOB</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)     */// boucherb@users 20030801 - method implemented//#ifdef JAVA2    public void setClob(int i, Clob x) throws SQLException {        if (x instanceof jdbcClob) {            setParameter(i, ((jdbcClob) x).data);            return;        } else if (x == null) {            setParameter(i, null);            return;        }        checkSetParameterIndex(i, false);        final long length = x.length();        if (length > Integer.MAX_VALUE) {            String msg = "Max Clob input character length exceeded: "                         + length;            throw Util.sqlException(Trace.INPUTSTREAM_ERROR, msg);        }        java.io.Reader     reader = x.getCharacterStream();        final StringBuffer sb     = new StringBuffer();        final int          size   = 2048;        final char[]       buff   = new char[size];        try {            for (int left = (int) 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(i, sb.toString());    }//#endif JAVA2    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given <code>Array</code> object.     * The driver converts this to an SQL <code>ARRAY</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 ARRAY 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 <code>Array</code> object that maps an SQL <code>ARRAY</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 setArray(int i, Array x) throws SQLException {        throw Util.notSupported();    }    /**     * <!-- start generic documentation -->     * Retrieves a <code>ResultSetMetaData</code> object that contains     * information about the columns of the <code>ResultSet</code> object     * that will be returned when this <code>PreparedStatement</code> object     * is executed.     * <P>     * Because a <code>PreparedStatement</code> object is precompiled, it is     * possible to know about the <code>ResultSet</code> object that it will     * return without having to execute it.  Consequently, it is possible     * to invoke the method <code>getMetaData</code> on a     * <code>PreparedStatement</code> object rather than waiting to execute     * it and then invoking the <code>ResultSet.getMetaData</code> method     * on the <code>ResultSet</code> object that is returned.     * <P>     * <B>NOTE:</B> Using this method may be expensive for some drivers due     * to the lack of underlying DBMS support. <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.  If the statement     * generates an update count, then null is returned.     *     * </div>     * <!-- end release-specific documentation -->     * @return the description of a <code>ResultSet</code> object's columns or     *    <code>null</code> if the driver cannot return a     *    <code>ResultSetMetaData</code> object     * @exception SQLException if a database access error occurs     * @since JDK 1.2 (JDK 1.1.x developers: read the new overview for     *   jdbcPreparedStatement)     */// boucherb@users 20030801 - method implemented    public ResultSetMetaData getMetaData() throws SQLException {        checkClosed();        if (isRowCount) {            return null;        }        if (rsmd == null) {            rsmd = new jdbcResultSetMetaData(rsmdDescriptor,                                             connection.connProperties);        }        return rsmd;    }    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given <code>java.sql.Date</code>     * value, using the given <code>Calendar</code> object.  The driver uses     * the <code>Calendar</code> object to construct an SQL <code>DATE</code>     * value,which the driver then sends to the database.  With a     * a <code>Calendar</code> object, the driver can calculate the date     * taking into account a custom timezone.  If no     * <code>Calendar</code> object is specified, the driver uses the default     * timezone, which is that of the virtual machine running the     * application. <p>     * <!-- end generic documentation -->     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value     * @param cal the <code>Calendar</code> object the driver will use     *       to construct the date     * @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 20020414 - patch 517028 by peterhudson@users - method defined// changes by fredt - moved conversion to HsqlDateTime    public void setDate(int parameterIndex, Date x,                        Calendar cal) throws SQLException {        String s;        try {            s = HsqlDateTime.getDateString(x, cal);        } catch (Exception e) {            throw Util.sqlException(Trace.INVALID_ESCAPE, e.toString());        }        setParameter(parameterIndex, s);    }    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given <code>java.sql.Time</code>     * value, using the given <code>Calendar</code> object.  The driver uses     * the <code>Calendar</code> object to construct an SQL <code>TIME</code>     * value, which the driver then sends to the database.  With a     * a <code>Calendar</code> object, the driver can calculate the time     * taking into account a custom timezone.  If no     * <code>Calendar</code> object is specified, the driver uses the default     * timezone, which is that of the virtual machine running the     * application. <p>     * <!-- end generic documentation -->     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value     * @param cal the <code>Calendar</code> object the driver will use     *       to construct the time     * @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 20020414 - patch 517028 by peterhudson@users - method defined// changes by fredt - moved conversion to HsqlDateTime    public void setTime(int parameterIndex, Time x,                        Calendar cal) throws SQLException {        String s;        try {            s = HsqlDateTime.getTimeString(x, cal);        } catch (Exception e) {            throw Util.sqlException(Trace.INVALID_ESCAPE, e.toString());        }        setParameter(parameterIndex, s);    }    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given <code>java.sql.Timestamp</code>     * value, using the given <code>Calendar</code> object.  The driver uses     * the <code>Calendar</code> object to construct an SQL <code>TIMESTAMP</code>     * value, which the driver then sends to the database.  With a     * <code>Calendar</code> object, the driver can calculate the timestamp     * taking into account a custom timezone.  If no     * <code>Calendar</code> object is specified, the driver uses the default     * timezone, which is that of the virtual machine running the application. <p>     * <!-- end generic documentation 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -