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


Java Clob類代碼示例

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


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

示例1: testClobTruncate

import java.sql.Clob; //導入依賴的package包/類
/**
 * Tests for fix to BUG#1130
 * 
 * @throws Exception
 *             if the test fails
 */
public void testClobTruncate() throws Exception {
    createTable("testClobTruncate", "(field1 TEXT)");
    this.stmt.executeUpdate("INSERT INTO testClobTruncate VALUES ('abcdefg')");

    this.rs = this.stmt.executeQuery("SELECT * FROM testClobTruncate");
    this.rs.next();

    Clob clob = this.rs.getClob(1);
    clob.truncate(3);

    Reader reader = clob.getCharacterStream();
    char[] buf = new char[8];
    int charsRead = reader.read(buf);

    String clobAsString = new String(buf, 0, charsRead);

    assertTrue(clobAsString.equals("abc"));
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:25,代碼來源:ResultSetRegressionTest.java

示例2: setClobAsAsciiStream

import java.sql.Clob; //導入依賴的package包/類
@Override
public void setClobAsAsciiStream(
		PreparedStatement ps, int paramIndex, final InputStream asciiStream, int contentLength)
	throws SQLException {

	if (asciiStream != null) {
		Clob clob = (Clob) createLob(ps, true, new LobCallback() {
			@Override
			public void populateLob(Object lob) throws Exception {
				Method methodToInvoke = lob.getClass().getMethod("getAsciiOutputStream", (Class[]) null);
				OutputStream out = (OutputStream) methodToInvoke.invoke(lob, (Object[]) null);
				FileCopyUtils.copy(asciiStream, out);
			}
		});
		ps.setClob(paramIndex, clob);
		if (logger.isDebugEnabled()) {
			logger.debug("Set ASCII stream for Oracle CLOB with length " + clob.length());
		}
	}
	else {
		ps.setClob(paramIndex, (Clob) null);
		logger.debug("Set Oracle CLOB to null");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:OracleLobHandler.java

示例3: setClobAsString

import java.sql.Clob; //導入依賴的package包/類
@Override
public void setClobAsString(PreparedStatement ps, int paramIndex, final String content)
	throws SQLException {

	if (content != null) {
		Clob clob = (Clob) createLob(ps, true, new LobCallback() {
			@Override
			public void populateLob(Object lob) throws Exception {
				Method methodToInvoke = lob.getClass().getMethod("getCharacterOutputStream", (Class[]) null);
				Writer writer = (Writer) methodToInvoke.invoke(lob, (Object[]) null);
				FileCopyUtils.copy(content, writer);
			}
		});
		ps.setClob(paramIndex, clob);
		if (logger.isDebugEnabled()) {
			logger.debug("Set string for Oracle CLOB with length " + clob.length());
		}
	}
	else {
		ps.setClob(paramIndex, (Clob) null);
		logger.debug("Set Oracle CLOB to null");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:OracleLobHandler.java

示例4: setClobAsAsciiStream

import java.sql.Clob; //導入依賴的package包/類
@Override
public void setClobAsAsciiStream(
		PreparedStatement ps, int paramIndex, InputStream asciiStream, int contentLength)
		throws SQLException {

	if (streamAsLob) {
		if (asciiStream != null) {
			try {
				ps.setClob(paramIndex, new InputStreamReader(asciiStream, "US-ASCII"), contentLength);
			}
			catch (UnsupportedEncodingException ex) {
				throw new SQLException("US-ASCII encoding not supported: " + ex);
			}
		}
		else {
			ps.setClob(paramIndex, (Clob) null);
		}
	}
	else if (wrapAsLob) {
		if (asciiStream != null) {
			ps.setClob(paramIndex, new PassThroughClob(asciiStream, contentLength));
		}
		else {
			ps.setClob(paramIndex, (Clob) null);
		}
	}
	else {
		ps.setAsciiStream(paramIndex, asciiStream, contentLength);
	}
	if (logger.isDebugEnabled()) {
		logger.debug(asciiStream != null ? "Set ASCII stream for CLOB with length " + contentLength :
				"Set CLOB to null");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:35,代碼來源:DefaultLobHandler.java

示例5: setClob

import java.sql.Clob; //導入依賴的package包/類
/**
 * JDBC 2.0 Set a CLOB parameter.
 * 
 * @param i
 *            the first parameter is 1, the second is 2, ...
 * @param x
 *            an object representing a CLOB
 * 
 * @throws SQLException
 *             if a database error occurs
 */
public void setClob(int i, Clob x) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (x == null) {
            setNull(i, Types.CLOB);
        } else {

            String forcedEncoding = this.connection.getClobCharacterEncoding();

            if (forcedEncoding == null) {
                setString(i, x.getSubString(1L, (int) x.length()));
            } else {
                try {
                    setBytes(i, StringUtils.getBytes(x.getSubString(1L, (int) x.length()), forcedEncoding));
                } catch (UnsupportedEncodingException uee) {
                    throw SQLError.createSQLException("Unsupported character encoding " + forcedEncoding, SQLError.SQL_STATE_ILLEGAL_ARGUMENT,
                            getExceptionInterceptor());
                }
            }

            this.parameterTypes[i - 1 + getParameterIndexOffset()] = Types.CLOB;
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:35,代碼來源:PreparedStatement.java

示例6: testBug20453671

import java.sql.Clob; //導入依賴的package包/類
/**
 * Tests fix for BUG#20453671 - CLOB.POSITION() API CALL WITH CLOB INPUT RETURNS EXCEPTION
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20453671() throws Exception {
    this.rs = this.stmt.executeQuery("select 'abcd', 'a', 'b', 'c', 'd', 'e'");
    this.rs.next();

    final Clob in = this.rs.getClob(1);
    final ResultSet locallyScopedRs = this.rs;
    assertThrows(SQLException.class, "Illegal starting position for search, '0'", new Callable<Void>() {
        public Void call() throws Exception {
            in.position(locallyScopedRs.getClob(2), 0);
            return null;
        }
    });
    assertThrows(SQLException.class, "Starting position for search is past end of CLOB", new Callable<Void>() {
        public Void call() throws Exception {
            in.position(locallyScopedRs.getClob(2), 10);
            return null;
        }
    });

    assertEquals(1, in.position(this.rs.getClob(2), 1));
    assertEquals(2, in.position(this.rs.getClob(3), 1));
    assertEquals(3, in.position(this.rs.getClob(4), 1));
    assertEquals(4, in.position(this.rs.getClob(5), 1));
    assertEquals(-1, in.position(this.rs.getClob(6), 1));
}
 
開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:32,代碼來源:BlobRegressionTest.java

示例7: getString

import java.sql.Clob; //導入依賴的package包/類
public String getString(int columnIndex) throws ParseException {
    try {
        String valueString;
        if(DatabaseDataSet.this.metaData.getColumnType(this.getDatabaseColumnIndex(columnIndex)) == 2005) {
            Clob e = DatabaseDataSet.this.resultSet.getClob(this.getDatabaseColumnIndex(columnIndex));
            if(e != null) {
                try {
                    valueString = Tools.readTextFile(e.getCharacterStream());
                } catch (IOException var5) {
                    throw new ParseException(var5.getMessage(), var5);
                }
            } else {
                valueString = null;
            }
        } else {
            valueString = DatabaseDataSet.this.resultSet.getString(this.getDatabaseColumnIndex(columnIndex));
        }

        return DatabaseDataSet.this.resultSet.wasNull()?null:valueString;
    } catch (SQLException var6) {
        throw new ParseException(var6.getMessage(), var6);
    }
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:24,代碼來源:DatabaseDataSet.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.
 *
 * @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
 * @throws SQLException if there is an error accessing the
 *   <code>CLOB</code> value
 */
public synchronized long position(Clob searchstr,
                                  long start) throws SQLException {

    if (!isInLimits(Long.MAX_VALUE, start - 1, 0)) {
        throw JDBCUtil.outOfRangeArgument();
    }

    if (searchstr instanceof JDBCClobClient) {
        ClobDataID searchClob = ((JDBCClobClient) searchstr).clob;

        try {
            return clob.position(session, searchClob, start - 1);
        } catch (HsqlException e) {
            throw JDBCUtil.sqlException(e);
        }
    }

    return position(searchstr.getSubString(1, (int) searchstr.length()),
                    start);
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:34,代碼來源:JDBCClobClient.java

示例9: testParamSettingWhenUnsupportedTypeSaysUnsupported

import java.sql.Clob; //導入依賴的package包/類
/** Tests that "not supported" has priority over possible "type not supported"
 *  check. */
@Test( expected = SQLFeatureNotSupportedException.class )
public void testParamSettingWhenUnsupportedTypeSaysUnsupported() throws SQLException {
  PreparedStatement prepStmt = connection.prepareStatement( "VALUES 1" );
  try {
    prepStmt.setClob( 2, (Clob) null );
  }
  catch ( final SQLFeatureNotSupportedException e ) {
    assertThat(
        "Check whether params.-unsupported wording changed or checks changed.",
        e.toString(), PARAMETERS_NOT_SUPPORTED_MSG_MATCHER );
    throw e;
  }
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:16,代碼來源:PreparedStatementTest.java

示例10: buildJdbcJavaClassMappings

import java.sql.Clob; //導入依賴的package包/類
private static ConcurrentHashMap<Class, Integer> buildJdbcJavaClassMappings() {
	ConcurrentHashMap<Class, Integer> jdbcJavaClassMappings = new ConcurrentHashMap<Class, Integer>();

	// these mappings are the ones outlined specifically in the spec
	jdbcJavaClassMappings.put( String.class, Types.VARCHAR );
	jdbcJavaClassMappings.put( BigDecimal.class, Types.NUMERIC );
	jdbcJavaClassMappings.put( Boolean.class, Types.BIT );
	jdbcJavaClassMappings.put( Integer.class, Types.INTEGER );
	jdbcJavaClassMappings.put( Long.class, Types.BIGINT );
	jdbcJavaClassMappings.put( Float.class, Types.REAL );
	jdbcJavaClassMappings.put( Double.class, Types.DOUBLE );
	jdbcJavaClassMappings.put( byte[].class, Types.LONGVARBINARY );
	jdbcJavaClassMappings.put( java.sql.Date.class, Types.DATE );
	jdbcJavaClassMappings.put( Time.class, Types.TIME );
	jdbcJavaClassMappings.put( Timestamp.class, Types.TIMESTAMP );
	jdbcJavaClassMappings.put( Blob.class, Types.BLOB );
	jdbcJavaClassMappings.put( Clob.class, Types.CLOB );
	jdbcJavaClassMappings.put( Array.class, Types.ARRAY );
	jdbcJavaClassMappings.put( Struct.class, Types.STRUCT );
	jdbcJavaClassMappings.put( Ref.class, Types.REF );
	jdbcJavaClassMappings.put( Class.class, Types.JAVA_OBJECT );

	// additional "common sense" registrations
	jdbcJavaClassMappings.put( Character.class, Types.CHAR );
	jdbcJavaClassMappings.put( char[].class, Types.VARCHAR );
	jdbcJavaClassMappings.put( Character[].class, Types.VARCHAR );
	jdbcJavaClassMappings.put( Byte[].class, Types.LONGVARBINARY );
	jdbcJavaClassMappings.put( java.util.Date.class, Types.TIMESTAMP );
	jdbcJavaClassMappings.put( Calendar.class, Types.TIMESTAMP );

	return jdbcJavaClassMappings;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:33,代碼來源:JdbcTypeJavaClassMappings.java

示例11: 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:Jugendhackt,項目名稱:OpenVertretung,代碼行數:25,代碼來源:ServerPreparedStatement.java

示例12: getClob

import java.sql.Clob; //導入依賴的package包/類
/**Added by Jilali Raki. Needed for ROA
 * 
 * @param nColNumber  Column number
 * @return Serial Clob data
 * @throws TechnicalException
 */
public SerialClob getClob(int nColNumber) throws TechnicalException
{		
	if(m_resultSet != null)
	{
		try
		{
			Clob blVal = m_resultSet.getClob(nColNumber);
			SerialClob sb = new SerialClob(blVal); 
			return sb;
		}
		catch (SQLException e)
		{
			forceCloseOnExceptionCatched();
			ProgrammingException.throwException(ProgrammingException.DB_ERROR_RESULT_SET_COL_ACCESS_INT+nColNumber, m_csQuery, e);
		}			
	}
	return null;
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:25,代碼來源:SQLClause.java

示例13: getClob

import java.sql.Clob; //導入依賴的package包/類
/**
 * @see java.sql.CallableStatement#getClob(int)
 */
public Clob getClob(int parameterIndex) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        ResultSetInternalMethods rs = getOutputParameters(parameterIndex);

        Clob retValue = rs.getClob(mapOutputParameterIndexToRsIndex(parameterIndex));

        this.outputParamWasNull = rs.wasNull();

        return retValue;
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:15,代碼來源:CallableStatement.java

示例14: testValue

import java.sql.Clob; //導入依賴的package包/類
protected boolean testValue(final Object value) {
    if (value == null) {
        return false;
    }
    final String valueStr;
    if (value instanceof Blob) {
        valueStr = LobHelper.blobToString((Blob) value);
    } else if (value instanceof Clob) {
        valueStr = LobHelper.clobToString((Clob) value);
    } else {
        valueStr = value.toString();
    }
    switch (mode) {
        case LITERAL_FIND:
            if (filterStr == null || filterStr.length() == 0) {
            return true;
        } else {
            return valueStr.toUpperCase().contains(filterStr.toUpperCase());
        }
        case LITERAL_MATCH:
            if (filterStr == null || filterStr.length() == 0) {
            return true;
        } else {
            return filterStr.equals(valueStr);
        }
        case REGEX_FIND:
            return pattern.matcher(valueStr).find();
        case REGEX_MATCH:
            return pattern.matcher(valueStr).matches();
        default:
            throw new RuntimeException(UNKOWN_MODE);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:SuperPatternFilter.java

示例15: getClob

import java.sql.Clob; //導入依賴的package包/類
public Clob getClob(String parameterName) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getClob(parameterName);
        }
        throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);

    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
    return null;
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:13,代碼來源:CallableStatementWrapper.java


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