Пример #1
0
  @Override
  public int save(java.sql.Connection connection) {
    int i = 0;
    int nParam = 1;
    CallableStatement callableStatement = null;

    mnLastDbActionResult = SLibConstants.UNDEFINED;

    try {
      callableStatement =
          connection.prepareCall("{ CALL mfgu_line_save(" + "?, ?, ?, ?, ?, " + "?, ?, ?) }");
      callableStatement.setInt(nParam++, mnPkMfgLineId);
      callableStatement.setString(nParam++, msMfgLine);
      callableStatement.setBoolean(nParam++, mbIsDeleted);
      callableStatement.setInt(nParam++, mnFkCostCenterId);
      callableStatement.setInt(nParam++, mbIsRegistryNew ? mnFkUserNewId : mnFkUserEditId);
      callableStatement.registerOutParameter(nParam++, java.sql.Types.INTEGER);
      callableStatement.registerOutParameter(nParam++, java.sql.Types.SMALLINT);
      callableStatement.registerOutParameter(nParam++, java.sql.Types.VARCHAR);
      callableStatement.execute();

      mnPkMfgLineId = callableStatement.getInt(nParam - 3);
      mnDbmsErrorId = callableStatement.getInt(nParam - 2);
      msDbmsError = callableStatement.getString(nParam - 1);

      mbIsRegistryNew = false;
      mnLastDbActionResult = SLibConstants.DB_ACTION_SAVE_OK;
    } catch (java.lang.Exception e) {
      mnLastDbActionResult = SLibConstants.DB_ACTION_SAVE_ERROR;
      SLibUtilities.printOutException(this, e);
    }

    return mnLastDbActionResult;
  }
  public static boolean actualizar(entPuerto entidad) throws Exception {
    boolean rpta = false;
    Connection conn = null;
    CallableStatement stmt = null;
    try {
      String sql =
          "UPDATE puerto SET nombre = ?,estado= ?,"
              + "usuario_responsable = ?,fecha_modificacion = GETDATE() WHERE id_puerto = ?;";

      conn = ConexionDAO.getConnection();
      stmt = conn.prepareCall(sql);
      stmt.setString(1, entidad.getNombre());
      stmt.setBoolean(2, entidad.getEstado());
      stmt.setString(3, entidad.getUsuario_responsable());
      stmt.setInt(4, entidad.getId_puerto());

      rpta = stmt.executeUpdate() == 1;
    } catch (Exception e) {
      throw new Exception("Error Actualizar " + e.getMessage(), e);
    } finally {
      try {
        stmt.close();
        conn.close();
      } catch (SQLException e) {
      }
    }
    return rpta;
  }
 public void setBoolean(String parameterName, boolean x) throws SQLException {
   checkOpen();
   try {
     _stmt.setBoolean(parameterName, x);
   } catch (SQLException e) {
     handleException(e);
   }
 }
 public void setBoolean(String parameterName, boolean x) throws SQLException {
   checkOpen();
   try {
     ((CallableStatement) _stmt).setBoolean(parameterName, x);
   } catch (SQLException e) {
     handleException(e);
   }
 }
  /** Test of setBoolean method, of inteface java.sql.CallableStatement. */
  public void testSetBoolean() throws Exception {
    println("setBoolean");

    setUpDualTable();

    java.sql.CallableStatement stmt = prepareCall("select ((1=1) or ?) from dual");

    stmt.setBoolean("@p1", true);
  }
Пример #6
0
  @Override
  public int save(java.sql.Connection connection) {
    int nParam = 1;
    java.sql.CallableStatement callableStatement = null;

    mnLastDbActionResult = SLibConstants.UNDEFINED;

    try {
      callableStatement =
          connection.prepareCall(
              "{ " + "CALL trn_dsm_nts_save(" + "?, ?, ?, ?, ?, " + "?, ?, ?, ?, ?) }");
      callableStatement.setInt(nParam++, mnPkYearId);
      callableStatement.setInt(nParam++, mnPkDocId);
      callableStatement.setInt(nParam++, mnPkNotesId);
      callableStatement.setString(nParam++, msNotes);
      callableStatement.setBoolean(nParam++, mbIsPrintable);
      callableStatement.setBoolean(nParam++, mbIsDeleted);
      callableStatement.setInt(nParam++, mnFkUserNewId);
      callableStatement.setInt(nParam++, mnFkUserEditId);
      callableStatement.registerOutParameter(nParam++, java.sql.Types.SMALLINT);
      callableStatement.registerOutParameter(nParam++, java.sql.Types.VARCHAR);
      callableStatement.execute();

      mnDbmsErrorId = callableStatement.getInt(nParam - 2);
      msDbmsError = callableStatement.getString(nParam - 1);

      if (mnDbmsErrorId != 0) {
        mnLastDbActionResult = SLibConstants.DB_ACTION_SAVE_ERROR;
      } else {
        mbIsRegistryNew = false;
        mnLastDbActionResult = SLibConstants.DB_ACTION_SAVE_OK;
      }
    } catch (java.lang.Exception e) {
      mnLastDbActionResult = SLibConstants.DB_ACTION_SAVE_ERROR;
      SLibUtilities.printOutException(this, e);
    }

    return mnLastDbActionResult;
  }
Пример #7
0
  /** Sets the boolean */
  @Override
  public void setBoolean(String parameterName, boolean x) throws SQLException {
    try {
      _cstmt.setBoolean(parameterName, x);
    } catch (SQLException e) {
      onSqlException(e);

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

      throw e;
    }
  }
Пример #8
0
  @Override
  public int save(java.sql.Connection connection) {
    int nParam = 1;
    CallableStatement callableStatement = null;

    mnLastDbActionResult = SLibConstants.UNDEFINED;

    try {
      callableStatement =
          connection.prepareCall("{ CALL erp.finu_tax_bas_save(" + "?, ?, ?, ?, ?, ?, ?) }");
      callableStatement.setInt(nParam++, mnPkTaxBasicId);
      callableStatement.setString(nParam++, msTaxBasic);
      callableStatement.setBoolean(nParam++, mbIsDeleted);
      callableStatement.setInt(nParam++, mbIsRegistryNew ? mnFkUserNewId : mnFkUserEditId);
      callableStatement.registerOutParameter(nParam++, java.sql.Types.SMALLINT);
      callableStatement.registerOutParameter(nParam++, java.sql.Types.SMALLINT);
      callableStatement.registerOutParameter(nParam++, java.sql.Types.CHAR);
      callableStatement.execute();

      mnPkTaxBasicId = callableStatement.getInt(nParam - 3);
      mnDbmsErrorId = callableStatement.getInt(nParam - 2);
      msDbmsError = callableStatement.getString(nParam - 1);

      if (mnDbmsErrorId != 0) {
        throw new Exception(msDbmsError);
      } else {
        // Save aswell the taxes

        nParam = 1;

        for (int i = 0; i < mvDbmsTaxes.size(); i++) {
          mvDbmsTaxes.get(i).setPkTaxBasicId(mnPkTaxBasicId);
          if (mvDbmsTaxes.get(i).save(connection) != SLibConstants.DB_ACTION_SAVE_OK) {
            throw new Exception(SLibConstants.MSG_ERR_DB_REG_SAVE_DEP);
          }
        }

        mbIsRegistryNew = false;
        mnLastDbActionResult = SLibConstants.DB_ACTION_SAVE_OK;
      }
    } catch (java.sql.SQLException e) {
      mnLastDbActionResult = SLibConstants.DB_ACTION_SAVE_ERROR;
      SLibUtilities.printOutException(this, e);
    } catch (java.lang.Exception e) {
      mnLastDbActionResult = SLibConstants.DB_ACTION_SAVE_ERROR;
      SLibUtilities.printOutException(this, e);
    }

    return mnLastDbActionResult;
  }
Пример #9
0
 /** @see java.sql.PreparedStatement#setBoolean(int, boolean) */
 public void setBoolean(int parameterIndex, boolean x) throws SQLException {
   original.setBoolean(parameterIndex, x);
 }
Пример #10
0
 /** @see java.sql.CallableStatement#setBoolean(java.lang.String, boolean) */
 public void setBoolean(String parameterName, boolean x) throws SQLException {
   original.setBoolean(parameterName, x);
 }
  @Override
  public void execute() {
    Connection dbConn = null;
    CallableStatement proc = null;
    try {
      dbConn = PostgresConnection.getDataSource().getConnection();
      dbConn.setAutoCommit(true);
      proc = dbConn.prepareCall("{call create_list(?,?,?,?,now()::timestamp)}");
      proc.setPoolable(true);

      proc.setString(1, map.get("name"));
      proc.setString(2, map.get("description"));
      proc.setInt(3, Integer.parseInt(map.get("creator_id")));
      proc.setBoolean(4, Boolean.parseBoolean(map.get("private")));
      proc.execute();

      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);
      }
    } catch (PSQLException e) {
      if (e.getMessage().contains("unique constraint")) {
        if (e.getMessage().contains("(name)")) {
          CommandsHelp.handleError(
              map.get("app"),
              map.get("method"),
              "List name already exists",
              map.get("correlation_id"),
              LOGGER);
        }
      }
      if (e.getMessage().contains("value too long")) {
        CommandsHelp.handleError(
            map.get("app"), map.get("method"), "Too long input", map.get("correlation_id"), LOGGER);
      }
      CommandsHelp.handleError(
          map.get("app"),
          map.get("method"),
          "List name already exists",
          map.get("correlation_id"),
          LOGGER);
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (SQLException e) {
      CommandsHelp.handleError(
          map.get("app"),
          map.get("method"),
          "List name already exists",
          map.get("correlation_id"),
          LOGGER);
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } finally {
      PostgresConnection.disconnect(null, proc, dbConn);
    }
  }
Пример #12
0
  private static void callSetMethod(CallableStatement cs, int arg, int type, StringBuilder strbuf)
      throws Throwable {
    switch (type) {
      case Types.BIT:
      case Types.BOOLEAN:
        strbuf.append("setBoolean(" + arg + ", true)");
        cs.setBoolean(arg, true);
        break;

      case Types.TINYINT:
        strbuf.append("setByte(" + arg + ", 6)");
        cs.setByte(arg, (byte) 6);
        break;

      case Types.SMALLINT:
        strbuf.append("setShort(" + arg + ", 66)");
        cs.setShort(arg, (short) 66);
        break;

      case Types.INTEGER:
        strbuf.append("setInt(" + arg + ", 666)");
        cs.setInt(arg, 666);
        break;

      case Types.BIGINT:
        strbuf.append("setLong(" + arg + ", 666)");
        cs.setLong(arg, 666);
        break;

      case Types.FLOAT:
      case Types.REAL:
        strbuf.append("setFLoat(" + arg + ", 666)");
        cs.setFloat(arg, 666);
        break;

      case Types.DOUBLE:
        strbuf.append("setDouble(" + arg + ", 666)");
        cs.setDouble(arg, 666);
        break;

      case Types.DECIMAL:
      case Types.NUMERIC:
        strbuf.append("setBigDecimal(" + arg + ", 666.666)");
        BigDecimalHandler.setBigDecimalString(cs, arg, "666.666");
        break;

      case Types.CHAR:
      case Types.VARCHAR:
      case Types.LONGVARCHAR:
        strbuf.append("setString(" + arg + ", \"Set via setString()\")");
        cs.setString(arg, "Set via setString()");
        break;

      case Types.BINARY:
      case Types.VARBINARY:
      case Types.LONGVARBINARY:
        strbuf.append("setBytes(" + arg + ", byte[])");
        byte[] myarray = new byte[16];
        myarray[0] = (byte) 255;
        cs.setBytes(arg, myarray);
        break;

      case Types.DATE:
        strbuf.append("setDate(" + arg + ", Date.valueOf(1999-09-09))");
        cs.setDate(arg, Date.valueOf("1999-09-09"));
        break;

      case Types.TIME:
        strbuf.append("setTime(" + arg + ", Time.valueOf(09:09:09))");
        cs.setTime(arg, Time.valueOf("09:09:09"));
        break;

      case Types.TIMESTAMP:
        strbuf.append("setTimestamp(" + arg + ", Timestamp.valueOf(1999-09-09 09:09:09.999))");
        cs.setTimestamp(arg, Timestamp.valueOf("1999-09-09 09:09:09.999"));
        break;

      case Types.OTHER:
        strbuf.append("setObject(" + arg + ", new BigInteger(666))");
        cs.setObject(arg, new BigInteger("666"));
        break;

      default:
        throw new Throwable("TEST ERROR: unexpected type " + type);
    }
  }
 public void setBoolean(String parameterName, boolean x) throws SQLException {
   passThru.setBoolean(parameterName, x);
 }
Пример #14
0
  /*
   * prepareStatement
   * This method follows the logic of preparedDataCommon.prepareStatement() except that since it is only
   * called for CFPROCPARAM's it doesn't need to iterate over the data VectorArrayList. Instead it only
   * needs to extract the one value.
   */
  private void prepareStatement(String paramName, CallableStatement CallStatmt, Connection _conn)
      throws dataNotSupportedException, cfmRunTimeException, SQLException {
    // Map the CFML type to a JDBC type
    int jType = getJdbcType(CallStatmt, cfSqlType);

    paramName = paramName.replace("@", "");

    if (passAsNull) {
      // JDBC drivers don't recognize ORACLE_NCLOB so we need to pass it in as a Types.CHAR
      if (jType == ORACLE_NCLOB) CallStatmt.setNull(paramName, Types.CHAR);
      else CallStatmt.setNull(paramName, jType);
      return;
    }

    // Get the value associated with this CFPROCPARAM
    cfData _data = data.get(0);

    switch (jType) {
        // for MS SQL Server via JDBC-ODBC Bridge, if you try to use setString()
        // instead of setObject(), it will pad VARCHAR columns when it shouldn't
      case Types.CHAR:
      case Types.VARCHAR:
        CallStatmt.setObject(paramName, _data.getString(), jType);
        break;

      case Types.LONGVARCHAR:
        CallStatmt.setObject(paramName, _data.getString(), jType);
        break;

      case ORACLE_NCLOB:
        CallStatmt.setObject(paramName, _data.getString(), jType);
        break;

      case Types.BINARY:
      case Types.VARBINARY:
      case Types.LONGVARBINARY:
        CallStatmt.setObject(paramName, ((cfBinaryData) _data).getByteArray(), jType);
        break;

      case Types.TINYINT:
      case Types.SMALLINT:
      case Types.INTEGER:
        if (_data.getNumber().isInt()) {
          CallStatmt.setInt(paramName, _data.getInt());
          break;
        }
        // if not an int, fall through to next case

      case Types.BIGINT:
        double d = _data.getDouble();
        if (d <= Long.MAX_VALUE) {
          if (isSetLongSupported(_conn)) {
            CallStatmt.setLong(paramName, _data.getLong());
          } else {
            CallStatmt.setDouble(paramName, d);
          }
        } else {
          CallStatmt.setDouble(paramName, d);
        }
        break;

      case Types.DECIMAL:
      case Types.NUMERIC:
        try {
          // NOTE: if a customer is complaining about losing decimal places then make sure they
          // are setting the scale properly in cfqueryparam. The default value for scale
          // is 0 which causes all decimal places to be removed.
          CallStatmt.setBigDecimal(
              paramName,
              new BigDecimal(_data.getDouble()).setScale(scale, BigDecimal.ROUND_HALF_UP));
          break;
        } catch (Exception e) {
          // fall through to next case
        }

      case Types.FLOAT:
      case Types.DOUBLE:
        CallStatmt.setDouble(paramName, _data.getDouble());
        break;

      case Types.REAL:
        CallStatmt.setFloat(paramName, new Float(_data.getDouble()).floatValue());
        break;

      case Types.DATE:
        long date =
            (_data.getDataType() == cfData.CFDATEDATA
                ? _data.getLong()
                : _data.getDateData().getLong());
        try {
          CallStatmt.setDate(paramName, new java.sql.Date(date));
        } catch (SQLException e) { // JDBC-ODBC Bridge doesn't support setDate() for MS SQL Server
          CallStatmt.setString(paramName, com.nary.util.Date.formatDate(date, "dd-MMM-yy"));
        }
        break;

      case Types.TIME:
        long time =
            (_data.getDataType() == cfData.CFDATEDATA
                ? _data.getLong()
                : _data.getDateData().getLong());
        try {
          CallStatmt.setTime(paramName, new java.sql.Time(time));
        } catch (SQLException e) { // JDBC-ODBC Bridge doesn't support setTime() for MS SQL Server
          CallStatmt.setString(paramName, com.nary.util.Date.formatDate(time, "hh:mm aa"));
        }
        break;

      case Types.TIMESTAMP:
        long ts =
            (_data.getDataType() == cfData.CFDATEDATA
                ? _data.getLong()
                : _data.getDateData().getLong());
        CallStatmt.setTimestamp(paramName, new java.sql.Timestamp(ts));
        break;

      case Types.BIT:
        CallStatmt.setBoolean(paramName, _data.getBoolean());
        break;

      case Types.NULL:
        CallStatmt.setNull(paramName, getJdbcType(CallStatmt, cfSqlType));
        break;

      default:
        throw newRunTimeException("Unsupported CFSQLTYPE: " + sqlType);
    }
  }