public Clob getClob(int i) throws SQLException {
   checkOpen();
   try {
     return _stmt.getClob(i);
   } catch (SQLException e) {
     handleException(e);
     return null;
   }
 }
 public Clob getClob(String parameterName) throws SQLException {
   checkOpen();
   try {
     return _stmt.getClob(parameterName);
   } catch (SQLException e) {
     handleException(e);
     return null;
   }
 }
Example #3
0
  /** The clob value */
  @Override
  public Clob getClob(String name) throws SQLException {
    try {
      return _cstmt.getClob(name);
    } catch (SQLException e) {
      onSqlException(e);

      throw e;
    } catch (RuntimeException e) {
      onRuntimeException(e);

      throw e;
    }
  }
  private StringBuffer getData() {

    StringBuffer tmp = new StringBuffer();
    Connection con = null;

    try {

      con = ds.getConnection();

      String sql = "{call ? := lau_utl.getMyGroupContext(?)}";
      CallableStatement stmt = con.prepareCall(sql);

      stmt.registerOutParameter(1, OracleTypes.CLOB);
      stmt.setString(2, userId);

      log.info(sql);
      stmt.execute();
      Clob clob = stmt.getClob(1);
      if (clob != null) {
        Reader reader = clob.getCharacterStream();
        CharArrayWriter writer = new CharArrayWriter();
        int i = -1;
        while ((i = reader.read()) != -1) {
          writer.write(i);
        }
        tmp.append(new String(writer.toCharArray()));
      }

      stmt.close();
      con.close();

    } catch (SQLException e) {
      log.error(e, e);
    } catch (Exception e) {
      log.error(e, e);
    } finally {
      try {
        if (con != null) con.close();
      } catch (Exception e) {
        log.error(e, e);
      }
    }
    // log.info(tmp);
    return tmp;
  }
  /** Test of getClob method, of inteface java.sql.CallableStatement. */
  public void testGetClob() throws Exception {
    println("getClob");

    if (!isTestOutParameters()) {
      return;
    }

    CallableStatement stmt;
    String expResult = "getString";
    Clob result = null;

    try {
      stmt = prepRegAndExec("{?= call cast('getClob' as longvarchar)}", 1, Types.LONGVARCHAR);

      result = stmt.getClob(1);
    } catch (Exception ex) {
      fail(ex.getMessage());
    }

    assertEquals(expResult, result.getSubString(1, (int) result.length()));
  }
Example #6
0
  @SuppressWarnings("unchecked")
  public static <T> T getFromStatement(ExecuteContext ctx, Class<? extends T> type, int index)
      throws SQLException {
    CallableStatement stmt = (CallableStatement) ctx.statement();

    if (type == Blob.class) {
      return (T) stmt.getBlob(index);
    } else if (type == Boolean.class) {
      return (T) checkWasNull(stmt, Boolean.valueOf(stmt.getBoolean(index)));
    } else if (type == BigInteger.class) {
      BigDecimal result = stmt.getBigDecimal(index);
      return (T) (result == null ? null : result.toBigInteger());
    } else if (type == BigDecimal.class) {
      return (T) stmt.getBigDecimal(index);
    } else if (type == Byte.class) {
      return (T) checkWasNull(stmt, Byte.valueOf(stmt.getByte(index)));
    } else if (type == byte[].class) {
      return (T) stmt.getBytes(index);
    } else if (type == Clob.class) {
      return (T) stmt.getClob(index);
    } else if (type == Date.class) {
      return (T) stmt.getDate(index);
    } else if (type == Double.class) {
      return (T) checkWasNull(stmt, Double.valueOf(stmt.getDouble(index)));
    } else if (type == Float.class) {
      return (T) checkWasNull(stmt, Float.valueOf(stmt.getFloat(index)));
    } else if (type == Integer.class) {
      return (T) checkWasNull(stmt, Integer.valueOf(stmt.getInt(index)));
    } else if (type == Long.class) {
      return (T) checkWasNull(stmt, Long.valueOf(stmt.getLong(index)));
    } else if (type == Short.class) {
      return (T) checkWasNull(stmt, Short.valueOf(stmt.getShort(index)));
    } else if (type == String.class) {
      return (T) stmt.getString(index);
    } else if (type == Time.class) {
      return (T) stmt.getTime(index);
    } else if (type == Timestamp.class) {
      return (T) stmt.getTimestamp(index);
    } else if (type == YearToMonth.class) {
      if (ctx.getDialect() == POSTGRES) {
        Object object = stmt.getObject(index);
        return (T) (object == null ? null : PostgresUtils.toYearToMonth(object));
      } else {
        String string = stmt.getString(index);
        return (T) (string == null ? null : YearToMonth.valueOf(string));
      }
    } else if (type == DayToSecond.class) {
      if (ctx.getDialect() == POSTGRES) {
        Object object = stmt.getObject(index);
        return (T) (object == null ? null : PostgresUtils.toDayToSecond(object));
      } else {
        String string = stmt.getString(index);
        return (T) (string == null ? null : DayToSecond.valueOf(string));
      }
    } else if (type == UByte.class) {
      String string = stmt.getString(index);
      return (T) (string == null ? null : UByte.valueOf(string));
    } else if (type == UShort.class) {
      String string = stmt.getString(index);
      return (T) (string == null ? null : UShort.valueOf(string));
    } else if (type == UInteger.class) {
      String string = stmt.getString(index);
      return (T) (string == null ? null : UInteger.valueOf(string));
    } else if (type == ULong.class) {
      String string = stmt.getString(index);
      return (T) (string == null ? null : ULong.valueOf(string));
    }

    // The type byte[] is handled earlier. byte[][] can be handled here
    else if (type.isArray()) {
      return (T) convertArray(stmt.getObject(index), (Class<? extends Object[]>) type);
    } else if (ArrayRecord.class.isAssignableFrom(type)) {
      return (T) getArrayRecord(ctx, stmt.getArray(index), (Class<? extends ArrayRecord<?>>) type);
    } else if (EnumType.class.isAssignableFrom(type)) {
      return getEnumType(type, stmt.getString(index));
    } else if (MasterDataType.class.isAssignableFrom(type)) {
      return (T) getMasterDataType(type, stmt.getString(index));
    } else if (UDTRecord.class.isAssignableFrom(type)) {
      switch (ctx.getDialect()) {
        case POSTGRES:
          return (T) pgNewUDTRecord(type, stmt.getObject(index));
      }

      return (T) stmt.getObject(index, DataTypes.udtRecords());
    } else if (Result.class.isAssignableFrom(type)) {
      ResultSet nested = (ResultSet) stmt.getObject(index);
      return (T) getNewFactory(ctx).fetch(nested);
    } else {
      return (T) stmt.getObject(index);
    }
  }
 /** @see java.sql.CallableStatement#getClob(java.lang.String) */
 public Clob getClob(String parameterName) throws SQLException {
   return original.getClob(parameterName);
 }
 /** @see java.sql.CallableStatement#getClob(int) */
 public Clob getClob(int i) throws SQLException {
   return original.getClob(i);
 }
 public Clob getClob(String parameterName) throws SQLException {
   return passThru.getClob(parameterName);
 }
 public Clob getClob(int i) throws SQLException {
   return passThru.getClob(i);
 }