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

📄 blobfromlocator.java

📁 在资料浩瀚的互联网中
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            if (blobRs.next()) {                return ((com.mysql.jdbc.ResultSet) blobRs).getBytes(1, true);            }            throw new SQLException("BLOB data not found! Did primary keys change?",                SQLError.SQL_STATE_GENERAL_ERROR);        } finally {            if (blobRs != null) {                try {                    blobRs.close();                } catch (SQLException sqlEx) {                    ; // do nothing                }                blobRs = null;            }            if (pStmt != null) {                try {                    pStmt.close();                } catch (SQLException sqlEx) {                    ; // do nothing                }                pStmt = null;            }        }    }    /**     * Returns the number of bytes in the BLOB value designated by this Blob     * object.     *     * @return the length of this blob     *     * @throws SQLException if a database error occurs     */    public long length() throws SQLException {        java.sql.ResultSet blobRs = null;        java.sql.PreparedStatement pStmt = null;        // FIXME: Needs to use identifiers for column/table names        StringBuffer query = new StringBuffer("SELECT LENGTH(");        query.append(this.blobColumnName);        query.append(") FROM ");        query.append(this.tableName);        query.append(" WHERE ");        query.append((String) this.primaryKeyColumns.get(0));        query.append(" = ?");        for (int i = 1; i < this.numPrimaryKeys; i++) {            query.append(" AND ");            query.append((String) this.primaryKeyColumns.get(i));            query.append(" = ?");        }        try {            // FIXME: Have this passed in instead            pStmt = this.creatorResultSet.connection.prepareStatement(query.toString());            for (int i = 0; i < this.numPrimaryKeys; i++) {                pStmt.setString(i + 1, (String) this.primaryKeyValues.get(i));            }            blobRs = pStmt.executeQuery();            if (blobRs.next()) {                return blobRs.getLong(1);            }            throw new SQLException("BLOB data not found! Did primary keys change?",                SQLError.SQL_STATE_GENERAL_ERROR);        } finally {            if (blobRs != null) {                try {                    blobRs.close();                } catch (SQLException sqlEx) {                    ; // do nothing                }                blobRs = null;            }            if (pStmt != null) {                try {                    pStmt.close();                } catch (SQLException sqlEx) {                    ; // do nothing                }                pStmt = null;            }        }    }    /**     * Finds the position of the given pattern in this BLOB.     *     * @param pattern the pattern to find     * @param start where to start finding the pattern     *     * @return the position where the pattern is found in the BLOB, -1 if not     *         found     *     * @throws SQLException if a database error occurs     */    public long position(java.sql.Blob pattern, long start)        throws SQLException {        return position(pattern.getBytes(0, (int) pattern.length()), start);    }    /**     * @see java.sql.Blob#position(byte[], long)     */    public long position(byte[] pattern, long start) throws SQLException {        java.sql.ResultSet blobRs = null;        java.sql.PreparedStatement pStmt = null;        // FIXME: Needs to use identifiers for column/table names        StringBuffer query = new StringBuffer("SELECT LOCATE(");        query.append("?, ");        query.append(this.blobColumnName);        query.append(", ");        query.append(start);        query.append(") FROM ");        query.append(this.tableName);        query.append(" WHERE ");        query.append((String) this.primaryKeyColumns.get(0));        query.append(" = ?");        for (int i = 1; i < this.numPrimaryKeys; i++) {            query.append(" AND ");            query.append((String) this.primaryKeyColumns.get(i));            query.append(" = ?");        }        try {            // FIXME: Have this passed in instead            pStmt = this.creatorResultSet.connection.prepareStatement(query.toString());            pStmt.setBytes(1, pattern);            for (int i = 0; i < this.numPrimaryKeys; i++) {                pStmt.setString(i + 2, (String) this.primaryKeyValues.get(i));            }            blobRs = pStmt.executeQuery();            if (blobRs.next()) {                return blobRs.getLong(1);            }            throw new SQLException("BLOB data not found! Did primary keys change?",                SQLError.SQL_STATE_GENERAL_ERROR);        } finally {            if (blobRs != null) {                try {                    blobRs.close();                } catch (SQLException sqlEx) {                    ; // do nothing                }                blobRs = null;            }            if (pStmt != null) {                try {                    pStmt.close();                } catch (SQLException sqlEx) {                    ; // do nothing                }                pStmt = null;            }        }    }    /**     * @see Blob#truncate(long)     */    public void truncate(long length) throws SQLException {        java.sql.PreparedStatement pStmt = null;        // FIXME: Needs to use identifiers for column/table names        StringBuffer query = new StringBuffer("UPDATE ");        query.append(this.tableName);        query.append(" SET ");        query.append(this.blobColumnName);        query.append(" = LEFT(");        query.append(this.blobColumnName);        query.append(", ");        query.append(length);        query.append(") WHERE ");        query.append((String) this.primaryKeyColumns.get(0));        query.append(" = ?");        for (int i = 1; i < this.numPrimaryKeys; i++) {            query.append(" AND ");            query.append((String) this.primaryKeyColumns.get(i));            query.append(" = ?");        }        try {            // FIXME: Have this passed in instead            pStmt = this.creatorResultSet.connection.prepareStatement(query.toString());            for (int i = 0; i < this.numPrimaryKeys; i++) {                pStmt.setString(i + 1, (String) this.primaryKeyValues.get(i));            }            int rowsUpdated = pStmt.executeUpdate();            if (rowsUpdated != 1) {                throw new SQLException("BLOB data not found! Did primary keys change?",                    SQLError.SQL_STATE_GENERAL_ERROR);            }        } finally {            if (pStmt != null) {                try {                    pStmt.close();                } catch (SQLException sqlEx) {                    ; // do nothing                }                pStmt = null;            }        }    }}

⌨️ 快捷键说明

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