java类java.sql.Clob的实例源码

ResultSetRegressionTest.java 文件源码 项目:BibliotecaPS 阅读 33 收藏 0 点赞 0 评论 0
/**
 * 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"));
}
OracleLobHandler.java 文件源码 项目:lams 阅读 26 收藏 0 点赞 0 评论 0
@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");
    }
}
OracleLobHandler.java 文件源码 项目:lams 阅读 29 收藏 0 点赞 0 评论 0
@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");
    }
}
DefaultLobHandler.java 文件源码 项目:lams 阅读 22 收藏 0 点赞 0 评论 0
@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");
    }
}
PreparedStatement.java 文件源码 项目:lams 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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;
        }
    }
}
BlobRegressionTest.java 文件源码 项目:ProyectoPacientes 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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));
}
DatabaseDataSet.java 文件源码 项目:rapidminer 阅读 23 收藏 0 点赞 0 评论 0
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);
    }
}
JDBCClobClient.java 文件源码 项目:OpenDiabetes 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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);
}
PreparedStatementTest.java 文件源码 项目:QDrill 阅读 31 收藏 0 点赞 0 评论 0
/** 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;
  }
}
JdbcTypeJavaClassMappings.java 文件源码 项目:lams 阅读 30 收藏 0 点赞 0 评论 0
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;
}
ServerPreparedStatement.java 文件源码 项目:OpenVertretung 阅读 38 收藏 0 点赞 0 评论 0
/**
 * @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;
            }
        }
    }
}
SQLClause.java 文件源码 项目:ChronoBike 阅读 26 收藏 0 点赞 0 评论 0
/**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;
}
BlobRegressionTest.java 文件源码 项目:the-vigilantes 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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));
}
CallableStatement.java 文件源码 项目:the-vigilantes 阅读 35 收藏 0 点赞 0 评论 0
/**
 * @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;
    }
}
SuperPatternFilter.java 文件源码 项目:incubator-netbeans 阅读 27 收藏 0 点赞 0 评论 0
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);
    }
}
CallableStatementWrapper.java 文件源码 项目:the-vigilantes 阅读 25 收藏 0 点赞 0 评论 0
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;
}
SQLOutputImplTests.java 文件源码 项目:jdk8u-jdk 阅读 54 收藏 0 点赞 0 评论 0
@Test(enabled = true)
public void test06() throws Exception {
    Clob c = new StubClob();
    outImpl.writeClob(c);
    SerialClob sc = (SerialClob) results.get(0);
    assertTrue(c.getSubString(1,
            (int) c.length()).equals(sc.getSubString(1, (int) sc.length())));
}
BlobRegressionTest.java 文件源码 项目:OpenVertretung 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Tests fix for BUG#20453712 - CLOB.SETSTRING() WITH VALID INPUT RETURNS EXCEPTION
 * server-side prepared statements and streaming BINARY data.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20453712() throws Exception {
    final String s1 = "NewClobData";
    this.rs = this.stmt.executeQuery("select 'a'");
    this.rs.next();
    final Clob c1 = this.rs.getClob(1);

    // check with wrong position
    assertThrows(SQLException.class, "Starting position can not be < 1", new Callable<Void>() {
        public Void call() throws Exception {
            c1.setString(0, s1, 7, 4);
            return null;
        }
    });

    // check with wrong substring index
    assertThrows(SQLException.class, "String index out of range: 12", new Callable<Void>() {
        public Void call() throws Exception {
            c1.setString(1, s1, 8, 4);
            return null;
        }
    });

    // full replace
    c1.setString(1, s1, 3, 4);
    assertEquals("Clob", c1.getSubString(1L, (int) c1.length()));

    // add
    c1.setString(5, s1, 7, 4);
    assertEquals("ClobData", c1.getSubString(1L, (int) c1.length()));

    // replace middle chars
    c1.setString(2, s1, 7, 4);
    assertEquals("CDataata", c1.getSubString(1L, (int) c1.length()));
}
CallableStatementWrapper.java 文件源码 项目:ProyectoPacientes 阅读 22 收藏 0 点赞 0 评论 0
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;
}
AbstractLobCreator.java 文件源码 项目:lams 阅读 29 收藏 0 点赞 0 评论 0
@Override
public Clob wrap(Clob clob) {
    if ( NClob.class.isInstance( clob ) ) {
        return wrap( (NClob) clob );
    }
    else {
        return SerializableClobProxy.generateProxy( clob );
    }
}
OracleLobHandler.java 文件源码 项目:lams 阅读 28 收藏 0 点赞 0 评论 0
@Override
public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException {
    logger.debug("Returning Oracle CLOB as character stream");
    Clob clob = rs.getClob(columnIndex);
    initializeResourcesBeforeRead(rs.getStatement().getConnection(), clob);
    Reader retVal = (clob != null ? clob.getCharacterStream() : null);
    releaseResourcesAfterRead(rs.getStatement().getConnection(), clob);
    return retVal;
}
ContextualLobCreator.java 文件源码 项目:lams 阅读 26 收藏 0 点赞 0 评论 0
@Override
public Clob createClob(String string) {
    try {
        final Clob clob = createClob();
        clob.setString( 1, string );
        return clob;
    }
    catch ( SQLException e ) {
        throw new JDBCException( "Unable to set CLOB string after creation", e );
    }
}
CallableStatement.java 文件源码 项目:BibliotecaPS 阅读 33 收藏 0 点赞 0 评论 0
/**
 * @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;
    }
}
CallableStatementWrapper.java 文件源码 项目:BibliotecaPS 阅读 30 收藏 0 点赞 0 评论 0
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;
}
JDBCPreparedStatement.java 文件源码 项目:sstore-soft 阅读 28 收藏 0 点赞 0 评论 0
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());
    }
}
PreparedStatementTest.java 文件源码 项目:dremio-oss 阅读 33 收藏 0 点赞 0 评论 0
/** Tests that "not supported" has priority over possible "type not supported"
 *  check. */
@Test( expected = SQLFeatureNotSupportedException.class )
public void testParamSettingWhenUnsupportedTypeSaysUnsupported() throws SQLException {
  try(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;
    }
  }
}
ClobTypeHandler.java 文件源码 项目:tangyuan2 阅读 22 收藏 0 点赞 0 评论 0
@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;
}
CallableStatement.java 文件源码 项目:OpenVertretung 阅读 35 收藏 0 点赞 0 评论 0
/**
 * @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;
    }
}
BlobRegressionTest.java 文件源码 项目:the-vigilantes 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Tests fix for BUG#20453712 - CLOB.SETSTRING() WITH VALID INPUT RETURNS EXCEPTION
 * server-side prepared statements and streaming BINARY data.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20453712() throws Exception {
    final String s1 = "NewClobData";
    this.rs = this.stmt.executeQuery("select 'a'");
    this.rs.next();
    final Clob c1 = this.rs.getClob(1);

    // check with wrong position
    assertThrows(SQLException.class, "Starting position can not be < 1", new Callable<Void>() {
        public Void call() throws Exception {
            c1.setString(0, s1, 7, 4);
            return null;
        }
    });

    // check with wrong substring index
    assertThrows(SQLException.class, "String index out of range: 12", new Callable<Void>() {
        public Void call() throws Exception {
            c1.setString(1, s1, 8, 4);
            return null;
        }
    });

    // full replace
    c1.setString(1, s1, 3, 4);
    assertEquals("Clob", c1.getSubString(1L, (int) c1.length()));

    // add
    c1.setString(5, s1, 7, 4);
    assertEquals("ClobData", c1.getSubString(1L, (int) c1.length()));

    // replace middle chars
    c1.setString(2, s1, 7, 4);
    assertEquals("CDataata", c1.getSubString(1L, (int) c1.length()));
}
CallableStatement.java 文件源码 项目:lams 阅读 28 收藏 0 点赞 0 评论 0
/**
 * @see java.sql.CallableStatement#getClob(java.lang.String)
 */
public Clob getClob(String parameterName) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be from ?=

        Clob retValue = rs.getClob(fixParameterName(parameterName));

        this.outputParamWasNull = rs.wasNull();

        return retValue;
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号