@Override
  public boolean eliminarDireccionPersona(Persona persona, Connection conexion)
      throws SQLException {
    boolean resultado = false;
    CallableStatement cs = null;
    String sql = "{ ? = call negocio.fn_eliminardirecciones(?,?,?) }";

    try {
      cs = conexion.prepareCall(sql);
      int i = 1;
      cs.registerOutParameter(i++, Types.BOOLEAN);
      cs.setInt(i++, persona.getCodigoEntero().intValue());
      cs.setString(i++, UtilJdbc.convertirMayuscula(persona.getUsuarioModificacion()));
      cs.setString(i++, persona.getIpModificacion());

      cs.execute();
      resultado = cs.getBoolean(1);
    } catch (SQLException e) {
      resultado = false;
      throw new SQLException(e);
    } finally {
      try {
        if (cs != null) {
          cs.close();
        }
      } catch (SQLException e) {
        throw new SQLException(e);
      }
    }
    return resultado;
  }
  @Override
  public boolean eliminarInvitadosNovios(ProgramaNovios programaNovios, Connection conn)
      throws SQLException, Exception {
    boolean resultado = false;
    CallableStatement cs = null;
    String sql = "{ ? = call negocio.fn_eliminarinvitadosnovios(?,?,?) }";
    try {
      cs = conn.prepareCall(sql);
      int i = 1;
      cs.registerOutParameter(i++, Types.BOOLEAN);
      cs.setInt(i++, programaNovios.getCodigoEntero().intValue());
      cs.setString(i++, programaNovios.getUsuarioModificacion());
      cs.setString(i++, programaNovios.getIpModificacion());
      cs.execute();

      resultado = cs.getBoolean(1);
    } catch (SQLException e) {
      resultado = false;
      throw new SQLException(e);
    } finally {
      try {
        if (cs != null) {
          cs.close();
        }

      } catch (SQLException e) {
        throw new SQLException(e);
      }
    }

    return resultado;
  }
Пример #3
0
  private static boolean isLTxIdCommitted(LogicalTransactionId ltxid, Connection conn)
      throws SQLException {
    CallableStatement cstmt = null;

    cstmt = conn.prepareCall(GET_LTXID_OUTCOME);
    cstmt.setObject(1, ltxid);
    cstmt.registerOutParameter(2, OracleTypes.BIT);
    cstmt.registerOutParameter(3, OracleTypes.BIT);
    cstmt.execute();
    boolean committed = cstmt.getBoolean(2);
    boolean callCompleted = cstmt.getBoolean(3);
    logger.info("call completed: " + callCompleted + ", committed: " + committed);
    cstmt.close();

    return committed;
  }
 public boolean getBoolean(String parameterName) throws SQLException {
   checkOpen();
   try {
     return _stmt.getBoolean(parameterName);
   } catch (SQLException e) {
     handleException(e);
     return false;
   }
 }
  public void testInOut() throws Throwable {
    try {
      Statement stmt = con.createStatement();
      stmt.execute(createBitTab);
      stmt.execute(insertBitTab);
      boolean ret =
          stmt.execute(
              "create or replace function "
                  + "insert_bit( inout IMAX boolean, inout IMIN boolean, inout INUL boolean)  as "
                  + "'begin "
                  + "insert into bit_tab values( imax, imin, inul);"
                  + "select max_val into imax from bit_tab;"
                  + "select min_val into imin from bit_tab;"
                  + "select null_val into inul from bit_tab;"
                  + " end;' "
                  + "language plpgsql;");
    } catch (Exception ex) {
      fail(ex.getMessage());
      throw ex;
    }
    try {
      CallableStatement cstmt = con.prepareCall("{ call insert_bit(?,?,?) }");
      cstmt.setObject(1, "true", Types.BIT);
      cstmt.setObject(2, "false", Types.BIT);
      cstmt.setNull(3, Types.BIT);
      cstmt.registerOutParameter(1, Types.BIT);
      cstmt.registerOutParameter(2, Types.BIT);
      cstmt.registerOutParameter(3, Types.BIT);
      cstmt.executeUpdate();

      assertTrue(cstmt.getBoolean(1));
      assertFalse(cstmt.getBoolean(2));
      cstmt.getBoolean(3);
      assertTrue(cstmt.wasNull());
    } finally {
      try {
        Statement dstmt = con.createStatement();
        dstmt.execute("drop function insert_bit(boolean, boolean, boolean)");
      } catch (Exception ex) {
      }
    }
  }
 public void testGetBoolean01() throws Throwable {
   try {
     Statement stmt = con.createStatement();
     stmt.execute(createBitTab);
     stmt.execute(insertBitTab);
     boolean ret =
         stmt.execute(
             "create or replace function "
                 + "bit_proc( OUT IMAX boolean, OUT IMIN boolean, OUT INUL boolean)  as "
                 + "'begin "
                 + "select max_val into imax from bit_tab;"
                 + "select min_val into imin from bit_tab;"
                 + "select null_val into inul from bit_tab;"
                 + " end;' "
                 + "language plpgsql;");
   } catch (Exception ex) {
     fail(ex.getMessage());
     throw ex;
   }
   try {
     CallableStatement cstmt = con.prepareCall("{ call bit_proc(?,?,?) }");
     cstmt.registerOutParameter(1, java.sql.Types.BIT);
     cstmt.registerOutParameter(2, java.sql.Types.BIT);
     cstmt.registerOutParameter(3, java.sql.Types.BIT);
     cstmt.executeUpdate();
     assertTrue(cstmt.getBoolean(1));
     assertFalse(cstmt.getBoolean(2));
     cstmt.getBoolean(3);
     assertTrue(cstmt.wasNull());
   } catch (Exception ex) {
     fail(ex.getMessage());
   } finally {
     try {
       Statement dstmt = con.createStatement();
       dstmt.execute("drop function bit_proc()");
     } catch (Exception ex) {
     }
   }
 }
Пример #7
0
  /** The boolean value */
  @Override
  public boolean getBoolean(String name) throws SQLException {
    try {
      return _cstmt.getBoolean(name);
    } catch (SQLException e) {
      onSqlException(e);

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

      throw e;
    }
  }
  public void test_wrapperOutputArgs() throws Exception {
    Connection conn = getConnection();
    PreparedStatement ps =
        conn.prepareStatement(
            "create procedure wrapperProc\n"
                + "(\n"
                + "    out bigintCol bigint,\n"
                + "    out booleanCol boolean,\n"
                + "    out doubleCol double,\n"
                + "    out floatCol float,\n"
                + "    out intCol int,\n"
                + "    out realCol real,\n"
                + "    out smallintCol smallint\n"
                + ")\n"
                + "language java\n"
                + "parameter style java\n"
                + "no sql\n"
                + "external name 'org.apache.derbyTesting.functionTests.tests.lang.AnsiSignatures.wrapperProc'\n");
    ps.execute();
    ps.close();

    CallableStatement cs = conn.prepareCall("call wrapperProc(  ?, ?, ?, ?, ?, ?, ? )");
    int param = 1;
    cs.registerOutParameter(param++, Types.BIGINT);
    cs.registerOutParameter(param++, Types.BOOLEAN);
    cs.registerOutParameter(param++, Types.DOUBLE);
    cs.registerOutParameter(param++, Types.FLOAT);
    cs.registerOutParameter(param++, Types.INTEGER);
    cs.registerOutParameter(param++, Types.REAL);
    cs.registerOutParameter(param++, Types.SMALLINT);

    cs.execute();
    param = 1;
    assertEquals(1L, cs.getLong(param++));
    assertEquals(true, cs.getBoolean(param++));
    assertEquals(1.0, cs.getDouble(param++), 0.0);
    assertEquals(1.0, cs.getDouble(param++), 0.0);
    assertEquals(1, cs.getInt(param++));
    assertEquals(1.0F, cs.getFloat(param++), 0.0F);
    assertEquals((short) 1, cs.getShort(param++));
  }
  /** Test of getBoolean method, of inteface java.sql.CallableStatement. */
  public void testGetBoolean() throws Exception {
    println("getBoolean");

    if (!isTestOutParameters()) {
      return;
    }

    CallableStatement stmt;
    boolean expResult = true;
    boolean result = false;

    try {
      stmt = prepRegAndExec("{?= call cast(true as boolean)}", 1, Types.BOOLEAN);

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

    assertEquals(expResult, result);
  }
  @Override
  public boolean ingresarServicioNovios(
      ServicioNovios servicioNovios, int idnovios, Connection conexion) throws SQLException {
    boolean resultado = false;
    CallableStatement cs = null;
    String sql = "{ ? = call negocio.fn_ingresarservicionovios(?,?,?,?,?,?,?,?) }";

    try {
      cs = conexion.prepareCall(sql);
      int i = 1;
      cs.registerOutParameter(i++, Types.BOOLEAN);
      cs.setInt(i++, idnovios);
      cs.setInt(i++, servicioNovios.getTipoServicio().getCodigoEntero().intValue());
      cs.setString(i++, servicioNovios.getDescripcionServicio());
      cs.setInt(i++, servicioNovios.getCantidad());
      cs.setBigDecimal(i++, servicioNovios.getPrecioUnitario());
      cs.setBigDecimal(i++, servicioNovios.getTotalServicio());
      cs.setString(i++, servicioNovios.getUsuarioCreacion());
      cs.setString(i++, servicioNovios.getIpCreacion());
      cs.execute();

      resultado = cs.getBoolean(1);
    } catch (SQLException e) {
      resultado = false;
      throw new SQLException(e);
    } finally {
      try {
        if (cs != null) {
          cs.close();
        }
      } catch (SQLException e) {
        throw new SQLException(e);
      }
    }

    return resultado;
  }
Пример #11
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);
    }
  }
Пример #12
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);
    }
  }
  @Override
  public void execute() {
    Connection dbConn = null;
    CallableStatement proc = null;
    try {
      dbConn = PostgresConnection.getDataSource().getConnection();
      dbConn.setAutoCommit(true);
      if (map.containsKey("image_url")) {
        proc = dbConn.prepareCall("{? = call create_dm(?,?,?,now()::timestamp,?))}");

      } else {
        proc = dbConn.prepareCall("{? = call create_dm(?,?,?,now()::timestamp)}");
      }

      proc.setPoolable(true);
      proc.registerOutParameter(1, Types.BOOLEAN);
      proc.setInt(2, Integer.parseInt(map.get("sender_id")));
      proc.setInt(3, Integer.parseInt(map.get("reciever_id")));
      proc.setString(4, map.get("dm_text"));
      if (map.containsKey("image_url")) {
        proc.setString(5, map.get("image_url"));
      }
      proc.execute();

      boolean sent = proc.getBoolean(1);

      if (sent) {
        MyObjectMapper mapper = new MyObjectMapper();
        JsonNodeFactory nf = JsonNodeFactory.instance;
        ObjectNode root = nf.objectNode();
        root.put("app", map.get("app"));
        root.put("method", map.get("method"));
        root.put("status", "ok");
        root.put("code", "200");
        try {
          CommandsHelp.submit(
              map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"), LOGGER);
        } catch (JsonGenerationException e) {
          LOGGER.log(Level.SEVERE, e.getMessage(), e);
        } catch (JsonMappingException e) {
          LOGGER.log(Level.SEVERE, e.getMessage(), e);
        } catch (IOException e) {
          LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }
      } else {
        CommandsHelp.handleError(
            map.get("app"),
            map.get("method"),
            "You can not dm a user who is not following you",
            map.get("correlation_id"),
            LOGGER);
      }

    } catch (PSQLException e) {
      if (e.getMessage().contains("value too long")) {
        CommandsHelp.handleError(
            map.get("app"),
            map.get("method"),
            "DM length cannot exceed 140 character",
            map.get("correlation_id"),
            LOGGER);
      } else {
        CommandsHelp.handleError(
            map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER);
      }

      LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (SQLException e) {
      CommandsHelp.handleError(
          map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER);
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } finally {
      PostgresConnection.disconnect(null, proc, dbConn);
    }
  }
 public boolean getBoolean(String parameterName) throws SQLException {
   return passThru.getBoolean(parameterName);
 }
Пример #15
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));
  }
 public boolean getBoolean(int parameterIndex) throws SQLException {
   return passThru.getBoolean(parameterIndex);
 }
Пример #17
0
 /** @see java.sql.CallableStatement#getBoolean(int) */
 public boolean getBoolean(int parameterIndex) throws SQLException {
   return original.getBoolean(parameterIndex);
 }
Пример #18
0
 /** @see java.sql.CallableStatement#getBoolean(java.lang.String) */
 public boolean getBoolean(String parameterName) throws SQLException {
   return original.getBoolean(parameterName);
 }
Пример #19
0
 /** {@inheritDoc} */
 @Override
 public Object get(CallableStatement cs, int index) throws SQLException {
   Object result = cs.getBoolean(index);
   if (cs.wasNull()) return null;
   else return result;
 }
Пример #20
0
  public boolean attaquer() {
    boolean reussite;
    boolean mort = false;
    int idTrollAdverse;
    int positionAdverseX = 0;
    int positionAdverseY = 0;
    if (idTroll == 1) {
      idTrollAdverse = 2;
    } else {
      idTrollAdverse = 1;
    }
    try {
      ResultSet rset =
          stmt.executeQuery(
              "select positionX, positionY from troll where idTroll=" + idTrollAdverse);
      rset.first();
      positionAdverseX = rset.getInt("positionX");
      positionAdverseY = rset.getInt("positionY");
    } catch (SQLException E) {
      System.err.println("SQLException: " + E.getMessage());
      System.err.println("SQLState:     " + E.getSQLState());
    }
    if (positionAdverseX == this.positionX && positionAdverseY == this.positionY) {
      reussite = loi_reussite();
      if (reussite) {
        int scoreAttaque = score_Des(att);
        System.out.println("Jet d'attaque : " + scoreAttaque);
        try {

          proc = conn.prepareCall("{? = call nb_des_esq(?)}");
          proc.registerOutParameter(1, Types.INTEGER);
          proc.setInt(2, idTrollAdverse);
          proc.executeUpdate();
          int esqAdverse = proc.getInt(1);
          proc.close();
          int scoreEsquiveAdversaire = score_Des(esqAdverse);
          System.out.println("Jet d'esquive de l'adversaire : " + scoreEsquiveAdversaire);
          if (scoreEsquiveAdversaire < scoreAttaque) {
            System.out.println("Esquive de l'adversaire ratée... PAF !!");
            int scoreDegats = score_Des(deg);
            System.out.print(
                "L'adversaire perd " + scoreDegats + " pts de vie, il lui en reste donc ");

            proc = conn.prepareCall("{? = call decrementer_vie(?,?)}");
            proc.registerOutParameter(1, Types.BOOLEAN);
            proc.setInt(2, idTrollAdverse);
            proc.setInt(3, scoreDegats);
            proc.executeUpdate();
            mort = proc.getBoolean(1);
            proc.close();

            ResultSet rset =
                stmt.executeQuery("select vie from troll where idTroll =" + idTrollAdverse);
            rset.first();
            System.out.println(rset.getInt("vie"));

            proc = conn.prepareCall("{call init_pa(?,?)}");
            proc.setInt(1, idTroll);
            proc.setInt(2, paRestants - 4);
            proc.executeUpdate();
            proc.close();

            paRestants = paRestants - 4;

          } else if (scoreEsquiveAdversaire == scoreAttaque) {
            System.out.println("Esquive de l'adversaire un peu tardive... PAF !!");
            int scoreDegats = score_Des(deg);
            System.out.println(
                "L'adversaire perd " + (scoreDegats / 2) + " pts de vie, il lui en reste donc ");
            proc = conn.prepareCall("{? = call decrementer_vie(?,?)}");
            proc.registerOutParameter(1, Types.BOOLEAN);
            proc.setInt(2, idTrollAdverse);
            proc.setInt(3, scoreDegats);
            proc.executeUpdate();
            mort = proc.getBoolean(1);
            proc.close();

            ResultSet rset =
                stmt.executeQuery("select vie from troll where idTroll =" + idTrollAdverse);
            rset.first();
            System.out.println(rset.getInt("vie"));

            proc = conn.prepareCall("{call init_pa(?,?)}");
            proc.setInt(1, idTroll);
            proc.setInt(2, paRestants - 4);
            proc.executeUpdate();
            proc.close();

            paRestants = paRestants - 4;
          } else {
            System.out.println(
                "Magnifique esquive de l'adversaire qui ne subira donc aucun dommage");
          }
        } catch (SQLException E) {
          System.err.println("SQLException: " + E.getMessage());
          System.err.println("SQLState:     " + E.getSQLState());
        }
      }
    } else {
      System.out.println("Le troll adverse n'est pas sur votre case !!");
    }
    return (mort);
  }