コード例 #1
0
 public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
   java.sql.Timestamp sqlTimestamp = cs.getTimestamp(columnIndex);
   if (cs.wasNull()) {
     return null;
   } else {
     return new java.util.Date(sqlTimestamp.getTime());
   }
 }
コード例 #2
0
 @Override
 public Date getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
   Timestamp sqlTimestamp = cs.getTimestamp(columnIndex);
   if (sqlTimestamp != null) {
     return new Date(sqlTimestamp.getTime());
   }
   return null;
 }
コード例 #3
0
 public Timestamp getTimestamp(int parameterIndex) throws SQLException {
   checkOpen();
   try {
     return _stmt.getTimestamp(parameterIndex);
   } catch (SQLException e) {
     handleException(e);
     return null;
   }
 }
コード例 #4
0
 public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
   checkOpen();
   try {
     return _stmt.getTimestamp(parameterName, cal);
   } catch (SQLException e) {
     handleException(e);
     return null;
   }
 }
コード例 #5
0
  /** The timestamp value */
  @Override
  public Timestamp getTimestamp(String name, Calendar cal) throws SQLException {
    try {
      return _cstmt.getTimestamp(name);
    } catch (SQLException e) {
      onSqlException(e);

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

      throw e;
    }
  }
コード例 #6
0
  /** The timestamp value */
  @Override
  public Timestamp getTimestamp(int i) throws SQLException {
    try {
      return _cstmt.getTimestamp(i);
    } catch (SQLException e) {
      onSqlException(e);

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

      throw e;
    }
  }
コード例 #7
0
ファイル: DbTimestampType.java プロジェクト: enenuki/phd
 /*  95:    */
 /*  96:    */ private Timestamp useCallableStatement(
     String callString, SessionImplementor session)
       /*  97:    */ {
   /*  98:122 */ CallableStatement cs = null;
   /*  99:    */ try
   /* 100:    */ {
     /* 101:124 */ cs =
         (CallableStatement)
             session
                 .getTransactionCoordinator()
                 .getJdbcCoordinator()
                 .getStatementPreparer()
                 .prepareStatement(callString, true);
     /* 102:    */
     /* 103:    */
     /* 104:    */
     /* 105:128 */ cs.registerOutParameter(1, 93);
     /* 106:129 */ cs.execute();
     /* 107:130 */ Timestamp ts = cs.getTimestamp(1);
     /* 108:131 */ if (LOG.isTraceEnabled()) {
       /* 109:132 */ LOG.tracev(
           "Current timestamp retreived from db : {0} (nanos={1}, time={2})",
           ts, Integer.valueOf(ts.getNanos()), Long.valueOf(ts.getTime()));
       /* 110:    */ }
     /* 111:134 */ return ts;
     /* 112:    */ }
   /* 113:    */ catch (SQLException e)
   /* 114:    */ {
     /* 115:137 */ throw session
         .getFactory()
         .getSQLExceptionHelper()
         .convert(e, "could not call current db timestamp function", callString);
     /* 116:    */ }
   /* 117:    */ finally
   /* 118:    */ {
     /* 119:144 */ if (cs != null) {
       /* 120:    */ try
       /* 121:    */ {
         /* 122:146 */ cs.close();
         /* 123:    */ }
       /* 124:    */ catch (SQLException sqle)
       /* 125:    */ {
         /* 126:149 */ LOG.unableToCleanUpCallableStatement(sqle);
         /* 127:    */ }
       /* 128:    */ }
     /* 129:    */ }
   /* 130:    */ }
コード例 #8
0
  /** Test of getTimestamp method, of inteface java.sql.CallableStatement. */
  public void testGetTimestamp() throws Exception {
    println("getTimestamp");

    if (!isTestOutParameters()) {
      return;
    }

    CallableStatement stmt;
    Timestamp expResult = Timestamp.valueOf("2005-12-13 11:23:02.1234");
    Timestamp result = null;

    try {
      stmt =
          prepRegAndExec(
              "{?= call cast('2005-12-13 11:23:02.1234' as timestamp(6))}", 1, Types.TIMESTAMP);

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

    assertEquals(expResult, result);
  }
コード例 #9
0
  /** @see java.sql.CallableStatement#getTimestamp(int, java.util.Calendar) */
  public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {

    return original.getTimestamp(parameterIndex, cal);
  }
コード例 #10
0
ファイル: FieldTypeHelper.java プロジェクト: Arbonaut/jOOQ
  @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);
    }
  }
コード例 #11
0
ファイル: DateTimeTypeHandler.java プロジェクト: dongxz/dbox
 public DateTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
   return toDateTime(cs.getTimestamp(columnIndex));
 }
コード例 #12
0
  /** @see java.sql.CallableStatement#getTimestamp(java.lang.String, java.util.Calendar) */
  public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {

    return original.getTimestamp(parameterName, cal);
  }
コード例 #13
0
  public void retrieveOutVariables(int ColIndex, cfSession _Session, CallableStatement _stmt)
      throws SQLException, cfmRunTimeException {
    boolean b;
    byte[] bin;
    int i;
    long l;
    double dbl;
    float flt;
    java.sql.Date dt;
    java.sql.Time t;
    Timestamp ts;
    ResultSet rs;
    String str;
    cfData outData = null;

    if (!isOUT()) return;

    switch (cfSqlType) {
      case CF_SQL_BIT:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          b = _stmt.getBoolean(paramName);
        } else {
          b = _stmt.getBoolean(ColIndex);
        }
        if (!_stmt.wasNull()) outData = cfBooleanData.getcfBooleanData(b);
        break;

      case CF_SQL_BINARY:
      case CF_SQL_VARBINARY:
      case CF_SQL_BLOB:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          bin = _stmt.getBytes(paramName);
        } else {
          bin = _stmt.getBytes(ColIndex);
        }

        if ((!_stmt.wasNull()) && (bin != null)) {
          outData = new cfBinaryData(bin);
        }
        break;

      case CF_SQL_SMALLINT:
      case CF_SQL_INTEGER:
      case CF_SQL_TINYINT:
        try {
          // With the Oracle JDBC driver, if we set the parameters using named parameters then
          // we must retrieve them using named parameters too.
          if (useNamedParameters) {
            i = _stmt.getInt(paramName);
          } else {
            i = _stmt.getInt(ColIndex);
          }

          if (!_stmt.wasNull()) outData = new cfNumberData(i);
        } catch (NumberFormatException e) {
          // With JDK 1.3 and the JDBC-ODBC bridge, the getInt() method will
          // throw a number format exception for in/out params so just ignore it.
          // Ignoring it allows us to retrieve the out param values.
        }
        break;

      case CF_SQL_BIGINT:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          l = _stmt.getLong(paramName);
        } else {
          l = _stmt.getLong(ColIndex);
        }

        if (!_stmt.wasNull()) outData = new cfNumberData(l);
        break;

      case CF_SQL_DECIMAL:
      case CF_SQL_NUMERIC:
        dbl = getBigDecimalAsDouble(_stmt, useNamedParameters, paramName, ColIndex);
        if (!_stmt.wasNull()) outData = new cfNumberData(dbl);
        break;

      case CF_SQL_DOUBLE:
      case CF_SQL_FLOAT:
      case CF_SQL_MONEY:
      case CF_SQL_MONEY4:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          dbl = _stmt.getDouble(paramName);
        } else {
          dbl = _stmt.getDouble(ColIndex);
        }

        if (!_stmt.wasNull()) outData = new cfNumberData(dbl);
        break;

      case CF_SQL_REAL:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          flt = _stmt.getFloat(paramName);
        } else {
          flt = _stmt.getFloat(ColIndex);
        }

        // For some reason casting a float to a double doesn't return a double
        // that exactly matches the original float so we'll use the less efficient
        // algorithm of converting the float to a string and the string to a double.
        // If for some reason this fails then we'll revert to casting the float to
        // a double.
        if (!_stmt.wasNull()) {
          try {
            dbl = Double.valueOf(Float.toString(flt)).doubleValue();
          } catch (Exception e) {
            dbl = (double) flt;
          }
          outData = new cfNumberData(dbl);
        }
        break;

      case CF_SQL_DATE:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          dt = _stmt.getDate(paramName);
        } else {
          dt = _stmt.getDate(ColIndex);
        }

        if ((!_stmt.wasNull()) && (dt != null)) {
          outData = new cfDateData(dt);
        }
        break;

      case CF_SQL_TIME:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          t = _stmt.getTime(paramName);
        } else {
          t = _stmt.getTime(ColIndex);
        }

        if ((!_stmt.wasNull()) && (t != null)) {
          outData = new cfDateData(t);
        }
        break;

      case CF_SQL_TIMESTAMP:
        try {
          // With the Oracle JDBC driver, if we set the parameters using named parameters then
          // we must retrieve them using named parameters too.
          if (useNamedParameters) {
            ts = _stmt.getTimestamp(paramName);
          } else {
            ts = _stmt.getTimestamp(ColIndex);
          }

          if ((!_stmt.wasNull()) && (ts != null)) {
            outData = new cfDateData(ts);
          }
        } catch (NullPointerException e) {
          // With JDK 1.3 and the JDBC-ODBC bridge, the getTimestamp() method will
          // throw a null ptr exception when the underlying value is null so just ignore it.
        }
        break;

      case CF_SQL_REFCURSOR:
        // This CF SQL Type is only used with Oracle for result sets returned by a
        // stored procedure.

        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          rs = (ResultSet) _stmt.getObject(paramName);
        } else {
          rs = (ResultSet) _stmt.getObject(ColIndex);
        }

        if ((!_stmt.wasNull()) && (rs != null)) {
          outData = new cfQueryResultData(rs, "Stored Procedure", maxLength);
        }
        break;

      default:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          str = _stmt.getString(paramName);
        } else {
          str = _stmt.getString(ColIndex);
        }

        if ((!_stmt.wasNull()) && (str != null)) {
          outData = new cfStringData(str);
        }
        break;
    }

    _Session.setData(outVariable, (outData == null ? cfNullData.NULL : outData));
  }
コード例 #14
0
 public Timestamp getTimestamp(int parameterIndex) throws SQLException {
   return passThru.getTimestamp(parameterIndex);
 }
コード例 #15
0
 /** @see java.sql.CallableStatement#getTimestamp(java.lang.String) */
 public Timestamp getTimestamp(String parameterName) throws SQLException {
   return original.getTimestamp(parameterName);
 }
コード例 #16
0
 /** @see java.sql.CallableStatement#getTimestamp(int) */
 public Timestamp getTimestamp(int parameterIndex) throws SQLException {
   return original.getTimestamp(parameterIndex);
 }
コード例 #17
0
  private static void callGetMethod(
      CallableStatement cs, int arg, int type, int paramType, StringBuilder strbuf)
      throws Throwable {
    switch (type) {
      case Types.BIT:
      case Types.BOOLEAN:
        strbuf.append("getBoolean(" + arg + ") = ");
        strbuf.append(cs.getBoolean(arg));
        break;

      case Types.TINYINT:
        strbuf.append("getByte(" + arg + ") = ");
        strbuf.append(Byte.toString(cs.getByte(arg)));
        break;

      case Types.SMALLINT:
        strbuf.append("getShort(" + arg + ") = ");
        strbuf.append(Short.toString(cs.getShort(arg)));
        break;

      case Types.INTEGER:
        strbuf.append("getInt(" + arg + ") = ");
        strbuf.append(Integer.toString(cs.getInt(arg)));
        break;

      case Types.BIGINT:
        strbuf.append("getLong(" + arg + ") = ");
        strbuf.append(Long.toString(cs.getLong(arg)));
        break;

      case Types.FLOAT:
      case Types.REAL:
        strbuf.append("getFloat(" + arg + ") = ");
        strbuf.append(Float.toString(cs.getFloat(arg)));
        break;

      case Types.DOUBLE:
        strbuf.append("getDouble(" + arg + ") = ");
        strbuf.append(Double.toString(cs.getDouble(arg)));
        break;

      case Types.DECIMAL:
      case Types.NUMERIC:
        strbuf.append("getBigDecimal(" + arg + ") = ");
        strbuf.append(BigDecimalHandler.getBigDecimalString(cs, arg, paramType));
        break;

      case Types.CHAR:
      case Types.VARCHAR:
      case Types.LONGVARCHAR:
        strbuf.append("getString(" + arg + ") = ");
        String s = cs.getString(arg);
        if (s.startsWith("[B@")) s = "byte[] reference";
        strbuf.append(s);
        break;

      case Types.BINARY:
      case Types.VARBINARY:
      case Types.LONGVARBINARY:
        strbuf.append("getBytes(" + arg + ") = ");
        byteArrayToString(cs.getBytes(arg), strbuf);
        break;

      case Types.DATE:
        strbuf.append("getDate(" + arg + ") = ");
        Date date = cs.getDate(arg);
        strbuf.append(date == null ? "null" : date.toString());
        break;

      case Types.TIME:
        strbuf.append("getTime(" + arg + ") = ");
        Time time = cs.getTime(arg);
        strbuf.append(time == null ? "null" : time.toString());
        break;

      case Types.TIMESTAMP:
        strbuf.append("getTimestamp(" + arg + ") = ");
        Timestamp timestamp = cs.getTimestamp(arg);
        strbuf.append(timestamp == null ? "null" : timestamp.toString());
        break;

      case Types.OTHER:
        strbuf.append("getObject(" + arg + ") = ");
        Object o = cs.getObject(arg);
        if (o == null) {
          strbuf.append("null");
        } else if (o instanceof byte[]) {
          byteArrayToString((byte[]) o, strbuf);
        } else {
          strbuf.append(o.toString());
        }

        break;

      default:
        throw new Throwable("TEST ERROR: unexpected type " + type);
    }
  }
コード例 #18
0
 public Timestamp getTimestamp(String parameterName) throws SQLException {
   return passThru.getTimestamp(parameterName);
 }