本文整理匯總了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"));
}
示例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");
}
}
示例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");
}
}
示例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");
}
}
示例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;
}
}
}
示例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));
}
示例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);
}
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
}
}
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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;
}