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


Java Clob.length方法代碼示例

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


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

示例1: clobToString

import java.sql.Clob; //導入方法依賴的package包/類
public static String clobToString(Clob clobValue) {
    StringBuilder contentPart = new StringBuilder();
    try {
        long size = clobValue.length();
        long retrievalCount = Math.min(size, 255);
        String sampleContent = clobValue.getSubString(1, (int) retrievalCount);
        contentPart.append(sampleContent.replaceAll("[\n\r]+", " "));//NOI18N
        if (size > 255) {
            contentPart.append(" [...]");                           //NOI18N
        }
        return contentPart.toString();
    } catch (SQLException ex) {
        LOG.log(Level.INFO,
                "Failed to retrieve CLOB content", //NOI18N
                ex);
        return clobToDescription(clobValue);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:LobHelper.java

示例2: clobToDescription

import java.sql.Clob; //導入方法依賴的package包/類
public static String clobToDescription(Clob clobValue) {
    StringBuilder clobDescription = new StringBuilder("<CLOB ");    //NOI18N

    try {
        long size = clobValue.length();
        if (size < 1000) {
            clobDescription.append(String.format("%1$d Chars", size)); //NOI18N
        } else if (size < 1000000) {
            clobDescription.append(String.format("%1$d kChars", size / 1000)); //NOI18N
        } else {
            clobDescription.append(String.format("%1$d MChars", size
                    / 1000000)); //NOI18N
        }
    } catch (SQLException ex) {
        clobDescription.append("of unknown size");                  //NOI18N
    }
    clobDescription.append(">");

    return clobDescription.toString();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:LobHelper.java

示例3: setClob

import java.sql.Clob; //導入方法依賴的package包/類
/**
 * @see java.sql.PreparedStatement#setClob(int, java.sql.Clob)
 */
@Override
public void setClob(int parameterIndex, Clob 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.getCharacterStream();
            binding.isLongData = true;

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

示例4: PreparedStmtSetValue

import java.sql.Clob; //導入方法依賴的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

示例5: getNullableResult

import java.sql.Clob; //導入方法依賴的package包/類
@Override
public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
	String value = "";
	Clob clob = rs.getClob(columnName);
	if (clob != null) {
		int size = (int) clob.length();
		value = clob.getSubString(1, size);
	}
	return value;
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:11,代碼來源:ClobTypeHandler.java

示例6: setClobForStringParameter

import java.sql.Clob; //導入方法依賴的package包/類
private void setClobForStringParameter(int parameterIndex,
        Clob x) throws SQLException {

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

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

        return;
    }
    checkSetParameterIndex(parameterIndex, false);

    final long length = x.length();

    if (length > Integer.MAX_VALUE) {
        String msg = "Max Clob input character length exceeded: " + length;    // NOI18N

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

    try {
        java.io.Reader  reader = x.getCharacterStream();
        CharArrayWriter writer = new CharArrayWriter(reader, (int) length);

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

示例7: ConvertClobToString

import java.sql.Clob; //導入方法依賴的package包/類
public static String ConvertClobToString(StringBuffer sb, Clob clob) throws SQLException, IOException{
	Reader reader = clob.getCharacterStream();
	char[] buffer = new char[(int)clob.length()];
	while(reader.read(buffer) != -1){
		sb.append(buffer);
	}
	return sb.toString();
}
 
開發者ID:experdb,項目名稱:eXperDB-DB2PG,代碼行數:9,代碼來源:DatabaseUtil.java

示例8: position

import java.sql.Clob; //導入方法依賴的package包/類
/**
     * Retrieves the character position at which the specified
     * <code>Clob</code> object <code>searchstr</code> appears in this
     * <code>Clob</code> object.  The search begins at position
     * <code>start</code>.
     *
     * @param searchstr the <code>Clob</code> object for which to search
     * @param start the position at which to begin searching; the first
     *              position is 1
     * @return the position at which the <code>Clob</code> object appears
     *              or -1 if it is not present; the first position is 1
     * @exception SQLException if there is an error accessing the
     *            <code>CLOB</code> value
     *
     * @since JDK 1.2, HSQLDB 1.7.2
     */
    public long position(final Clob searchstr,
                         long start) throws SQLException {

        if (searchstr == null) {
            return -1;
        }

        final String ldata = data;
        final long   dlen  = ldata.length();
        final long   sslen = searchstr.length();

        start--;    //***** FOIRGOT THIS *******

// This is potentially much less expensive than materializing a large
// substring from some other vendor's CLOB.  Indeed, we should probably
// do the comparison piecewise, using an in-memory buffer (or temp-files
// when available), if it is detected that the input CLOB is very long.
        if (start > dlen - sslen) {
            return -1;
        }

        // by now, we know sslen and start are both < Integer.MAX_VALUE
        String s;

        if (searchstr instanceof jdbcClob) {
            s = ((jdbcClob) searchstr).data;
        } else {
            s = searchstr.getSubString(1L, (int) sslen);
        }

        final int pos = ldata.indexOf(s, (int) start);

        return (pos < 0) ? -1
                         : pos + 1;
    }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:52,代碼來源:jdbcClob.java

示例9: position

import java.sql.Clob; //導入方法依賴的package包/類
/**
     * Retrieves the character position at which the specified
     * <code>Clob</code> object <code>searchstr</code> appears in this
     * <code>Clob</code> object.  The search begins at position
     * <code>start</code>.
     *
     * @param searchstr the <code>Clob</code> object for which to search
     * @param start the position at which to begin searching; the first
     *              position is 1
     * @return the position at which the <code>Clob</code> object appears
     *              or -1 if it is not present; the first position is 1
     * @exception SQLException if there is an error accessing the
     *            <code>CLOB</code> value
     *
     * @since JDK 1.2, HSQLDB 1.7.2
     */
    public long position(final Clob searchstr,
                         long start) throws SQLException {

        if (searchstr == null) {
            return -1;
        }

        final String ldata = data;
        final long   dlen  = ldata.length();
        final long   sslen = searchstr.length();

// This is potentially much less expensive than materializing a large
// substring from some other vendor's CLOB.  Indeed, we should probably
// do the comparison piecewise, using an in-memory buffer (or temp-files
// when available), if it is detected that the input CLOB is very long.
        if (start > dlen - sslen) {
            return -1;
        }

        // by now, we know sslen and start are both < Integer.MAX_VALUE
        String s;

        if (searchstr instanceof jdbcClob) {
            s = ((jdbcClob) searchstr).data;
        } else {
            s = searchstr.getSubString(1L, (int) sslen);
        }

        final int pos = ldata.indexOf(s, (int) start);

        return (pos < 0) ? -1
                         : pos + 1;
    }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:50,代碼來源:jdbcClob.java

示例10: position

import java.sql.Clob; //導入方法依賴的package包/類
/**
     * Retrieves the character position at which the specified
     * <code>Clob</code> object <code>searchstr</code> appears in this
     * <code>Clob</code> object.  The search begins at position
     * <code>start</code>.
     *
     * @param searchstr the <code>Clob</code> object for which to search
     * @param start the position at which to begin searching; the first
     *              position is 1
     * @return the position at which the <code>Clob</code> object appears
     *              or -1 if it is not present; the first position is 1
     * @exception SQLException if there is an error accessing the
     *            <code>CLOB</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 Clob searchstr,
                         long start) throws SQLException {

        final String ldata = data;

        checkValid(ldata);

        if (start < MIN_POS) {
            throw Util.outOfRangeArgument("start: " + start);
        }

        if (searchstr == null) {
            return -1;
        }

        final long dlen  = ldata.length();
        final long sslen = searchstr.length();

        start--;

// This is potentially much less expensive than materializing a large
// substring from some other vendor's CLOB.  Indeed, we should probably
// do the comparison piecewise, using an in-memory buffer (or temp-files
// when available), if it is detected that the input CLOB is very long.
        if (start > dlen - sslen) {
            return -1;
        }

        // by now, we know sslen and start are both < Integer.MAX_VALUE
        String s;

        if (searchstr instanceof JDBCClob) {
            s = ((JDBCClob) searchstr).data();
        } else {
            s = searchstr.getSubString(1L, (int) sslen);
        }

        final int pos = ldata.indexOf(s, (int) start);

        return (pos < 0) ? -1
                         : pos + 1;
    }
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:60,代碼來源:JDBCClob.java

示例11: setClob

import java.sql.Clob; //導入方法依賴的package包/類
/**
     * <!-- 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)
     */
// [email protected] 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());
    }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:78,代碼來源:jdbcPreparedStatement.java


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