當前位置: 首頁>>代碼示例>>Java>>正文


Java Blob.length方法代碼示例

本文整理匯總了Java中java.sql.Blob.length方法的典型用法代碼示例。如果您正苦於以下問題:Java Blob.length方法的具體用法?Java Blob.length怎麽用?Java Blob.length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.Blob的用法示例。


在下文中一共展示了Blob.length方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getObjectFromBlob

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * <p>
 * This method should be overridden by any delegate subclasses that need
 * special handling for BLOBs. The default implementation uses standard
 * JDBC <code>java.sql.Blob</code> operations.
 * </p>
 * 
 * @param rs
 *          the result set, already queued to the correct row
 * @param colName
 *          the column name for the BLOB
 * @return the deserialized Object from the ResultSet BLOB
 * @throws ClassNotFoundException
 *           if a class found during deserialization cannot be found
 * @throws IOException
 *           if deserialization causes an error
 */
protected Object getObjectFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    Object obj = null;

    Blob blobLocator = rs.getBlob(colName);
    if (blobLocator != null && blobLocator.length() != 0) {
        InputStream binaryInput = blobLocator.getBinaryStream();

        if (null != binaryInput) {
            if (binaryInput instanceof ByteArrayInputStream
                && ((ByteArrayInputStream) binaryInput).available() == 0 ) {
                //do nothing
            } else {
                ObjectInputStream in = new ObjectInputStream(binaryInput);
                try {
                    obj = in.readObject();
                } finally {
                    in.close();
                }
            }
        }

    }
    return obj;
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:43,代碼來源:StdJDBCDelegate.java

示例2: getObjectFromBlob

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * <p>
 * This method should be overridden by any delegate subclasses that need
 * special handling for BLOBs. The default implementation uses standard
 * JDBC <code>java.sql.Blob</code> operations.
 * </p>
 * 
 * @param rs
 *          the result set, already queued to the correct row
 * @param colName
 *          the column name for the BLOB
 * @return the deserialized Object from the ResultSet BLOB
 * @throws ClassNotFoundException
 *           if a class found during deserialization cannot be found
 * @throws IOException
 *           if deserialization causes an error
 */
protected Object getObjectFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    
    Object obj = null;

    Blob blobLocator = rs.getBlob(colName);
    InputStream binaryInput = null;
    try {
        if (null != blobLocator && blobLocator.length() > 0) {
            binaryInput = blobLocator.getBinaryStream();
        }
    } catch (Exception ignore) {
    }

    if (null != binaryInput) {
        ObjectInputStream in = new ObjectInputStream(binaryInput);
        try {
            obj = in.readObject();
        } finally {
            in.close();
        }
    }

    return obj;
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:43,代碼來源:WebLogicDelegate.java

示例3: getJobDetailFromBlob

import java.sql.Blob; //導入方法依賴的package包/類
protected Object getJobDetailFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    
    if (canUseProperties()) {
        Blob blobLocator = rs.getBlob(colName);
        InputStream binaryInput = null;
        try {
            if (null != blobLocator && blobLocator.length() > 0) {
                binaryInput = blobLocator.getBinaryStream();
            }
        } catch (Exception ignore) {
        }
        return binaryInput;
    }

    return getObjectFromBlob(rs, colName);
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:18,代碼來源:WebLogicDelegate.java

示例4: blobToString

import java.sql.Blob; //導入方法依賴的package包/類
public static String blobToString(Blob blob) {
    try {
        Long size = blob.length();
        StringBuilder stringValue = new StringBuilder();
        stringValue.append("<BLOB ");
        if (size < 1000) {
            stringValue.append(String.format("%1$d bytes", size));
        } else if (size < 1000000) {
            stringValue.append(String.format("%1$d kB", size / 1000));
        } else {
            stringValue.append(String.format("%1$d MB", size / 1000000));
        }
        stringValue.append(">");
        return stringValue.toString();
    } catch (SQLException ex) {
        return "<BLOB of unkown size>";
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:LobHelper.java

示例5: setBlobForBinaryParameter

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * Converts a blob to binary data for non-blob binary parameters.
 */
private void setBlobForBinaryParameter(int parameterIndex,
        Blob x) throws SQLException {

    if (x instanceof JDBCBlob) {
        setParameter(parameterIndex, ((JDBCBlob) x).data());

        return;
    } else if (x == null) {
        setParameter(parameterIndex, null);

        return;
    }

    final long length = x.length();

    if (length > Integer.MAX_VALUE) {
        String msg = "Maximum Blob input octet length exceeded: " + length;    // NOI18N

        throw JDBCUtil.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR, msg);
    }

    try {
        java.io.InputStream in = x.getBinaryStream();
        HsqlByteArrayOutputStream out = new HsqlByteArrayOutputStream(in,
            (int) length);

        setParameter(parameterIndex, out.toByteArray());
        out.close();
    } catch (Throwable e) {
        throw JDBCUtil.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR,
                                e.toString(), e);
    }
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:37,代碼來源:JDBCPreparedStatement.java

示例6: position

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * Retrieves the byte position in the <code>BLOB</code> value
 * designated by this <code>Blob</code> object at which
 * <code>pattern</code> begins.  The search begins at position
 * <code>start</code>.
 *
 * @param pattern the <code>Blob</code> object designating
 * the <code>BLOB</code> value for which to search
 * @param start the position in the <code>BLOB</code> value
 *        at which to begin searching; the first position is 1
 * @return the position at which the pattern begins, else -1
 * @exception SQLException if there is an error accessing the
 *            <code>BLOB</code> value or if start is less than 1
 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
 * this method
 * @since JDK 1.2, HSQLDB 1.7.2
 */
public long position(final Blob pattern, long start) throws SQLException {

    final byte[] data = getData();
    final int    dlen = data.length;

    if (start < MIN_POS) {
        throw JDBCUtil.outOfRangeArgument("start: " + start);
    } else if (start > dlen || pattern == null) {
        return -1L;
    }

    // by now, we know start <= Integer.MAX_VALUE;
    final int  startIndex = (int) start - 1;
    final long plen       = pattern.length();

    if (plen == 0 || startIndex > ((long) dlen) - plen) {
        return -1L;
    }

    // by now, we know plen <= Integer.MAX_VALUE
    final int iplen = (int) plen;
    byte[]    bytePattern;

    if (pattern instanceof JDBCBlob) {
        bytePattern = ((JDBCBlob) pattern).data();
    } else {
        bytePattern = pattern.getBytes(1L, iplen);
    }

    final int result = KMPSearchAlgorithm.search(data, bytePattern,
        KMPSearchAlgorithm.computeTable(bytePattern), startIndex);

    return (result == -1) ? -1
                          : result + 1;
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:53,代碼來源:JDBCBlob.java

示例7: setBlob

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * @see java.sql.PreparedStatement#setBlob(int, java.sql.Blob)
 */
@Override
public void setBlob(int parameterIndex, Blob x) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {

        if (x == null) {
            setNull(parameterIndex, java.sql.Types.BINARY);
        } else {
            BindValue binding = getBinding(parameterIndex, true);
            resetToType(binding, MysqlDefs.FIELD_TYPE_BLOB);

            binding.value = x;
            binding.isLongData = true;

            if (this.connection.getUseStreamLengthsInPrepStmts()) {
                binding.bindLength = x.length();
            } else {
                binding.bindLength = -1;
            }
        }
    }
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:25,代碼來源:ServerPreparedStatement.java

示例8: PreparedStmtSetValue

import java.sql.Blob; //導入方法依賴的package包/類
public static Object PreparedStmtSetValue(int columnType, ResultSet rs, int index) throws SQLException, IOException{
	StringBuffer sb = new StringBuffer();
	switch(columnType){
	case 2005:  //CLOB
		Clob clob = rs.getClob(index);
		
		if (clob == null){
			return null;
		}
		
		Reader reader = clob.getCharacterStream();
		char[] buffer = new char[(int)clob.length()];
		while(reader.read(buffer) != -1){
			sb.append(buffer);				
		}
		return sb.toString();
	case 2004:  //BLOB			
		Blob blob = rs.getBlob(index);
		
		if (blob == null){
			return null;
		}
		
		InputStream in = blob.getBinaryStream();
		byte[] Bytebuffer = new byte[(int)blob.length()];
		in.read(Bytebuffer);
		return Bytebuffer;
	case -2:
		return rs.getBytes(index);
	default:
		return rs.getObject(index);
	}	
}
 
開發者ID:experdb,項目名稱:eXperDB-DB2PG,代碼行數:34,代碼來源:DatabaseUtil.java

示例9: setBlobForBinaryParameter

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * Converts a blob to binary data for non-blob binary parameters.
 */
private void setBlobForBinaryParameter(int parameterIndex,
        Blob x) throws SQLException {

    if (x instanceof JDBCBlob) {
        setParameter(parameterIndex, ((JDBCBlob) x).data());

        return;
    } else if (x == null) {
        setParameter(parameterIndex, null);

        return;
    }
    checkSetParameterIndex(parameterIndex, true);

    final long length = x.length();

    if (length > Integer.MAX_VALUE) {
        String msg = "Maximum Blob input octet length exceeded: " + length;    // NOI18N

        throw Util.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR, msg);
    }

    try {
        java.io.InputStream in = x.getBinaryStream();
        HsqlByteArrayOutputStream out = new HsqlByteArrayOutputStream(in,
            (int) length);

        setParameter(parameterIndex, out.toByteArray());
    } catch (IOException e) {
        throw Util.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR,
                                e.toString());
    }
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:37,代碼來源:JDBCPreparedStatement.java

示例10: setBlob

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * @see java.sql.PreparedStatement#setBlob(int, java.sql.Blob)
 */
@Override
public void setBlob(int parameterIndex, Blob x) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {

        if (x == null) {
            setNull(parameterIndex, java.sql.Types.BINARY);
        } else {
            BindValue binding = getBinding(parameterIndex, true);
            setType(binding, MysqlDefs.FIELD_TYPE_BLOB);

            binding.value = x;
            binding.isNull = false;
            binding.isLongData = true;

            if (this.connection.getUseStreamLengthsInPrepStmts()) {
                binding.bindLength = x.length();
            } else {
                binding.bindLength = -1;
            }
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:ServerPreparedStatement.java

示例11: getObjectFromBlob

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 * <p>
 * Caché requires {@code java.sql.Blob} instances to be explicitly freed.
 */
@Override
protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException {
    Blob blob = rs.getBlob(colName);
    if (blob == null) {
        return null;
    } else {
        try {
            if (blob.length() == 0) {
                return null;
            } else {
                InputStream binaryInput = blob.getBinaryStream();
                if (binaryInput == null) {
                    return null;
                } else if (binaryInput instanceof ByteArrayInputStream && ((ByteArrayInputStream) binaryInput).available() == 0 ) {
                    return null;
                } else {
                    ObjectInputStream in = new ObjectInputStream(binaryInput);
                    try {
                        return in.readObject();
                    } finally {
                        in.close();
                    }
                }
            }
        } finally {
            blob.free();
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:35,代碼來源:CacheDelegate.java

示例12: get

import java.sql.Blob; //導入方法依賴的package包/類
protected Object get(ResultSet rs, String name) throws SQLException {
	Blob blob = rs.getBlob( name );
	if ( rs.wasNull() ) return null;
	int length = (int) blob.length();
	byte[] primaryResult = blob.getBytes( 1, length );
	return wrap( primaryResult );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:8,代碼來源:ByteArrayBlobType.java

示例13: setBlobForBinaryParameter

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * Converts a blob to binary data for non-blob binary parameters.
 */
private void setBlobForBinaryParameter(int parameterIndex,
        Blob x) throws SQLException {

    if (x instanceof JDBCBlob) {
        setParameter(parameterIndex, ((JDBCBlob) x).data());

        return;
    } else if (x == null) {
        setParameter(parameterIndex, null);

        return;
    }

    final long length = x.length();

    if (length > Integer.MAX_VALUE) {
        String msg = "Maximum Blob input octet length exceeded: " + length;    // NOI18N

        throw JDBCUtil.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR, msg);
    }

    try {
        java.io.InputStream in = x.getBinaryStream();
        HsqlByteArrayOutputStream out = new HsqlByteArrayOutputStream(in,
            (int) length);

        setParameter(parameterIndex, out.toByteArray());
    } catch (Throwable e) {
        throw JDBCUtil.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR,
                                e.toString(), e);
    }
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:36,代碼來源:JDBCPreparedStatement.java

示例14: position

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * Retrieves the byte position in the <code>BLOB</code> value
 * designated by this <code>Blob</code> object at which
 * <code>pattern</code> begins.  The search begins at position
 * <code>start</code>.
 *
 * @param pattern the <code>Blob</code> object designating
 *      the <code>BLOB</code> value for which to search
 * @param start the position in the <code>BLOB</code> value
 *        at which to begin searching; the first position is 1
 * @return the position at which the pattern begins, else -1
 * @exception SQLException if there is an error accessing the
 *        <code>BLOB</code> value
 *
 * @since JDK 1.2, HSQLDB 1.7.2
 */
public long position(final Blob pattern, long start) throws SQLException {

    final byte[] ldata = data;
    final int    dlen  = ldata.length;

    if (start > dlen || pattern == null) {
        return -1;
    } else if (start < 1) {
        start = 0;
    } else {
        start--;
    }

    final long plen = pattern.length();

    if (plen == 0 || start > ((long) dlen) - plen) {
        return -1;
    }

    // by now, we know plen <= Integer.MAX_VALUE
    final int iplen = (int) plen;
    byte[]    bap;

    if (pattern instanceof jdbcBlob) {
        bap = ((jdbcBlob) pattern).data;
    } else {
        bap = pattern.getBytes(1, iplen);
    }

    final int  stop = dlen - iplen;
    final byte b0   = bap[0];

    outer_loop:
    for (int i = (int) start; i <= stop; i++) {
        if (ldata[i] != b0) {
            continue;
        }

        int len     = iplen;
        int doffset = i;
        int poffset = 0;

        while (len-- > 0) {
            if (ldata[doffset++] != bap[poffset++]) {
                continue outer_loop;
            }
        }

        return i + 1;
    }

    return -1;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:70,代碼來源:jdbcBlob.java

示例15: position

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * Retrieves the byte position in the <code>BLOB</code> value
 * designated by this <code>Blob</code> object at which
 * <code>pattern</code> begins.  The search begins at position
 * <code>start</code>.
 *
 * @param pattern the <code>Blob</code> object designating
 * the <code>BLOB</code> value for which to search
 * @param start the position in the <code>BLOB</code> value
 *        at which to begin searching; the first position is 1
 * @return the position at which the pattern begins, else -1
 * @exception SQLException if there is an error accessing the
 *            <code>BLOB</code> value or if start is less than 1
 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
 * this method
 * @since JDK 1.2, HSQLDB 1.7.2
 */
public long position(final Blob pattern, long start) throws SQLException {

    final byte[] ldata = data;

    checkValid(ldata);

    final int dlen = ldata.length;

    if (start < MIN_POS) {
        throw Util.outOfRangeArgument("start: " + start);
    } else if (start > dlen || pattern == null) {
        return -1L;
    } else {
        start--;
    }

    final long plen = pattern.length();

    if (plen == 0 || start > ((long) dlen) - plen) {
        return -1L;
    }

    // by now, we know plen <= Integer.MAX_VALUE
    final int iplen = (int) plen;
    byte[]    bap;

    if (pattern instanceof JDBCBlob) {
        bap = ((JDBCBlob) pattern).data();
    } else {
        bap = pattern.getBytes(1L, iplen);
    }

    final int  stop = dlen - iplen;
    final byte b0   = bap[0];

    outer_loop:
    for (int i = (int) start; i <= stop; i++) {
        if (ldata[i] != b0) {
            continue;
        }

        int len     = iplen;
        int doffset = i;
        int poffset = 0;

        while (len-- > 0) {
            if (ldata[doffset++] != bap[poffset++]) {
                continue outer_loop;
            }
        }

        return i + 1;
    }

    return -1L;
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:74,代碼來源:JDBCBlob.java


注:本文中的java.sql.Blob.length方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。