public void addApplication(
      String appName,
      String description,
      int categoryID,
      BigDecimal price,
      int appVersion,
      BigDecimal appSize,
      int devID) {
    try {
      PreparedStatement statement =
          this.conn.prepareStatement(
              "INSERT INTO application "
                  + "(app_name, description, category_id, price, app_version, app_size, developer_id) "
                  + "VALUES (?, ?, ?, ?, ?, ?, ?)");
      statement.setString(1, appName);
      statement.setString(2, description);
      statement.setInt(3, categoryID);
      statement.setBigDecimal(4, price);
      statement.setInt(5, appVersion);
      statement.setBigDecimal(6, appSize);
      statement.setInt(7, devID);

      statement.executeUpdate();

      System.out.println(String.format("> Application %s sent to moderation\n", appName));
    } catch (SQLException exception) {
      printErrorForSQLException(exception);
    }
  }
Beispiel #2
0
  public boolean registrarCierre() {
    boolean resultado = false;
    Connection con = null;

    // SE CONSIGUE EL ITEM PARA EL CIERRE DE CAJA
    CierreCaja unCierre = this.getCierre();
    String sql =
        "INSERT INTO cierre_caja("
            + "fecha,"
            + "factura_inicial,"
            + "factura_final,"
            + "efectivo,"
            + "creditos,"
            + "totalventa,"
            + "tarjeta,"
            + "usuario,"
            + "isv15,"
            + "isv18)"
            + " VALUES (now(),?,?,?,?,?,?,?,?,?)";
    if (unCierre != null)
      try {
        con = Conexion.getPoolConexion().getConnection();
        registrarCierre = con.prepareStatement(sql);

        registrarCierre.setInt(1, unCierre.getNoFacturaInicio());
        registrarCierre.setInt(2, unCierre.getNoFacturaFinal());
        registrarCierre.setBigDecimal(3, unCierre.getEfectivo());
        registrarCierre.setBigDecimal(4, unCierre.getCredito());
        registrarCierre.setBigDecimal(5, unCierre.getTotal());
        registrarCierre.setBigDecimal(6, unCierre.getTarjeta());
        registrarCierre.setString(7, unCierre.getUsuario());
        registrarCierre.setBigDecimal(8, unCierre.getIsv15());
        registrarCierre.setBigDecimal(9, unCierre.getIsv18());

        registrarCierre.executeUpdate(); // se guarda el encabezado de la factura
        resultado = true;

      } catch (SQLException e) {
        e.printStackTrace();
        resultado = false;
      } finally {
        try {

          // if(res != null) res.close();
          if (registrarCierre != null) registrarCierre.close();
          if (con != null) con.close();

        } // fin de try
        catch (SQLException excepcionSql) {
          excepcionSql.printStackTrace();
          // conexion.desconectar();
        } // fin de catch
      } // fin de finally

    return resultado;
  }
Beispiel #3
0
  public boolean elementInstanceExist(String personId, BigDecimal entryId) {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      conn = getDataSource().getConnection();
      ps = conn.prepareStatement(SELECT_QUERY_SINGLE_COUNT);
      ps.setString(1, personId);
      ps.setBigDecimal(2, entryId);
      rs = ps.executeQuery();

      if (rs.next()) {
        if (rs.getInt(1) != 0) {
          return true;
        }
      } else {
        return false;
      }
    } catch (SQLException sqle) {
      logService.error("Exception caught when attempting to query name table.", sqle);
      throw new DataAccessException(sqle);
    } finally {
      close(conn, ps, rs);
    }

    return false;
  }
 public void updateBeneficiaries(Account account) {
   String sql = "update T_ACCOUNT_BENEFICIARY SET SAVINGS = ? where ACCOUNT_ID = ? and NAME = ?";
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = dataSource.getConnection();
     ps = conn.prepareStatement(sql);
     for (Beneficiary beneficiary : account.getBeneficiaries()) {
       ps.setBigDecimal(1, beneficiary.getSavings().asBigDecimal());
       ps.setLong(2, account.getEntityId());
       ps.setString(3, beneficiary.getName());
       ps.executeUpdate();
     }
   } catch (SQLException e) {
     throw new RuntimeException("SQL exception occurred updating beneficiary savings", e);
   } finally {
     if (ps != null) {
       try {
         // Close to prevent database cursor exhaustion
         ps.close();
       } catch (SQLException ex) {
       }
     }
     if (conn != null) {
       try {
         // Close to prevent database connection exhaustion
         conn.close();
       } catch (SQLException ex) {
       }
     }
   }
 }
  /**
   * Prepares the statement used to delete this object from the database.
   *
   * @param conn the database connection
   * @return the delete statement.
   * @exception java.sql.SQLException if an error occurs.
   */
  public PreparedStatement getDeleteStatement(DBConnection conn) throws SQLException {

    String sql = "delete from PersonalProfile \n" + "where " + getOIdColumnName() + " = ?";
    PreparedStatement stmt = conn.prepareStatement(sql);
    stmt.setBigDecimal(1, getOId().toBigDecimal());
    return stmt;
  }
Beispiel #6
0
  @RequestMapping(method = RequestMethod.POST)
  public @ResponseBody DataShop getShopInJSON(
      //            @RequestParam(value = "rehr_id", required = false) Integer  rehr_id,
      @RequestParam(value = "rehr_corp_id", required = false) Integer rehr_corp_id,
      @RequestParam(value = "rehr_post", required = false) String rehr_post,
      @RequestParam(value = "rehr_num", required = false) String rehr_num,
      @RequestParam(value = "rehr_salary", required = false) BigDecimal rehr_salary,
      @RequestParam(value = "rehr_sex_req", required = false) String rehr_sex_req,
      @RequestParam(value = "rehr_age_req", required = false) String rehr_age_req,
      @RequestParam(value = "rehr_requests", required = false) String rehr_requests)
      throws Exception {
    DataShop dataShop = new DataShop();
    dataShop.setSuccess(true);
    Connection conn = null;
    PreparedStatement pst = null;
    try {
      Class.forName("org.postgresql.Driver").newInstance();
    } catch (Exception e) {
      System.out.print(e.getMessage());
    }

    DBInfo connstr = new DBInfo();
    String url = connstr.getUrl();
    String user = connstr.getUser();
    String password = connstr.getPassword();

    try {
      conn = DriverManager.getConnection(url, user, password);

      String sql =
          "INSERT INTO work.tb_corp_rehr(\n"
              + "              rehr_corp_id, rehr_post, rehr_num, rehr_salary, rehr_sex_req, \n"
              + "            rehr_age_req, rehr_requests)\n"
              + "    VALUES (?, ?, ?, ?, ?, \n"
              + "            ?, ?)";
      pst = conn.prepareStatement(sql);
      pst.setInt(1, rehr_corp_id);
      pst.setString(2, rehr_post);
      pst.setString(3, rehr_num);
      pst.setBigDecimal(4, rehr_salary);
      pst.setString(5, rehr_sex_req);
      pst.setString(6, rehr_age_req);
      pst.setString(7, rehr_requests);
      pst.executeUpdate();

      dataShop.setSuccess(true);

    } catch (SQLException e) {
      System.out.print(e.getMessage());
    } finally {
      try {
        if (pst != null) pst.close();
        if (conn != null) conn.close();
      } catch (SQLException e) {
        System.out.print(e.getMessage());
      }
    }

    return dataShop;
  }
 private void writeToDatabase(Date time, Value<?> value) {
   try {
     Parameter<?> parameter = value.getParameter();
     if (!parameter.isNumeric()) {
       throw new IllegalArgumentException("The value '" + value.toString() + "' is not numeric!");
     }
     BigDecimal decimalValue = null;
     BigInteger integerValue = null;
     if (Long.class.isAssignableFrom(parameter.getType())) {
       integerValue = BigInteger.valueOf((Long) value.getValue());
     } else {
       decimalValue = BigDecimal.valueOf((Double) value.getValue());
     }
     preparedStatement.setTime(1, new Time(time.getTime()));
     preparedStatement.setString(2, server);
     preparedStatement.setString(3, parameter.getName());
     preparedStatement.setString(4, parameter.getUnit());
     preparedStatement.setString(5, parameter.getType().getName());
     preparedStatement.setString(6, parameter.getDescription());
     preparedStatement.setBigDecimal(7, decimalValue);
     preparedStatement.setLong(8, integerValue.longValue());
     preparedStatement.setString(9, parameter.getLevelOfMeasurement().name());
     preparedStatement.execute();
   } catch (SQLException e) {
     throw new RuntimeException("Could not insert event into event log.", e);
   }
 }
 private void handleNullValue(int i, PreparedStatement pstmt) throws SQLException {
   if (BigDecimal.class.equals(dataTypes.get(i))) {
     pstmt.setBigDecimal(i + 1, null);
   } else if (Boolean.class.equals(dataTypes.get(i))) {
     pstmt.setNull(i + 1, Types.BOOLEAN);
   } else if (Byte.class.equals(dataTypes.get(i))) {
     pstmt.setNull(i + 1, Types.SMALLINT);
   } else if (Date.class.equals(dataTypes.get(i))) {
     pstmt.setDate(i + 1, null);
   } else if (Double.class.equals(dataTypes.get(i))) {
     pstmt.setNull(i + 1, Types.DOUBLE);
   } else if (Float.class.equals(dataTypes.get(i))) {
     pstmt.setNull(i + 1, Types.FLOAT);
   } else if (Integer.class.equals(dataTypes.get(i))) {
     pstmt.setNull(i + 1, Types.INTEGER);
   } else if (Long.class.equals(dataTypes.get(i))) {
     pstmt.setNull(i + 1, Types.BIGINT);
   } else if (Short.class.equals(dataTypes.get(i))) {
     pstmt.setNull(i + 1, Types.SMALLINT);
   } else if (String.class.equals(dataTypes.get(i))) {
     pstmt.setString(i + 1, null);
   } else if (Time.class.equals(dataTypes.get(i))) {
     pstmt.setTime(i + 1, null);
   } else if (Timestamp.class.equals(dataTypes.get(i))) {
     pstmt.setTimestamp(i + 1, null);
   } else {
     throw new SQLException(
         "Data type not supported by SQLContainer: " + parameters.get(i).getClass().toString());
   }
 }
Beispiel #9
0
  /**
   * Method to fetch a single instance of a given element.
   *
   * @param personId of the user
   * @param entryId of the element @ if this element can not be located @ if there are any fetch
   *     problems.
   */
  public ElementDataObject findElementInstance(String personId, BigDecimal entryId) {
    Committee committee = new Committee();
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      conn = getDataSource().getConnection();
      ps = conn.prepareStatement(SELECT_QUERY_SINGLE);
      ps.setString(1, personId);
      ps.setBigDecimal(2, entryId);
      rs = ps.executeQuery();

      if (rs.next()) {
        committee.setPersonId(rs.getString("PERSON_ID"));
        committee.setEntryId(rs.getBigDecimal("ENTRY_ID"));
        committee.setDateCreated(rs.getTimestamp("DATE_CREATED"));
        committee.setModifiedDate(rs.getTimestamp("MODIFIED_DATE"));
        committee.setEntryName(rs.getString("ENTRY_NAME"));
        committee.setFromDate(rs.getTimestamp("FROM_DATE"));
        committee.setToDate(rs.getTimestamp("TO_DATE"));
        committee.setDescription(rs.getString("DESCRIPTION"));
      } else {
        return null;
      }
    } catch (SQLException sqle) {
      logService.error("Exception caught when attempting to query name table.", sqle);
      throw new DataAccessException(sqle);
    } finally {
      close(conn, ps, rs);
    }

    return committee;
  }
 public void setBigDecimal(int idx, BigDecimal dec) throws SQLException {
   try {
     addMementoEntry("setBigDecimal", new Class[] {BigDecimal.class}, idx, dec);
     wrapped.setBigDecimal(idx, dec);
   } catch (SQLException e) {
     throw new UcanaccessSQLException(e);
   }
 }
 public void insertRecognition(long contractNumber, Money money, MfDate recognitionDate)
     throws SQLException {
   PreparedStatement stmt = db.prepareStatement(insertRecognitionStatement);
   stmt.setLong(1, contractNumber);
   stmt.setDate(2, recognitionDate.toSqlDate());
   stmt.setBigDecimal(3, money.amount());
   stmt.executeUpdate();
 }
 @Override
 public void setBigDecimal(int paramIndex, BigDecimal value) throws DataLinkException {
   try {
     stmt.setBigDecimal(paramIndex, value);
   } catch (SQLException ex) {
     throw new DataLinkException(ex);
   }
 }
 public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
   checkOpen();
   try {
     _stmt.setBigDecimal(parameterIndex, x);
   } catch (SQLException e) {
     handleException(e);
   }
 }
Beispiel #14
0
  public void simpan(Produk p) throws Exception {
    psInsert.setString(1, p.getKode());
    psInsert.setString(2, p.getNama());
    psInsert.setBigDecimal(3, p.getHarga());
    psInsert.setDate(4, new java.sql.Date(p.getTerakhirUpdate().getTime()));

    hasil = psInsert.executeUpdate();
  }
  public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
    Profiler profiler = _profilerPoint.start();

    try {
      _preparedStatement.setBigDecimal(parameterIndex, x);
    } finally {
      profiler.finish();
    }
  }
  /**
   * Set the value into a PreparedStatement.
   *
   * @exception SQLException Error setting value in PreparedStatement
   */
  public final void setInto(PreparedStatement ps, int position) throws SQLException {

    if (isNull()) {
      ps.setNull(position, java.sql.Types.DECIMAL);
      return;
    }

    ps.setBigDecimal(position, getBigDecimal());
  }
 @Override
 public void processPrepared(PreparedStatement statement, AtomicInteger index) {
   try {
     statement.setBigDecimal(index.getAndIncrement(), new BigDecimal((String) literalValue));
   } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Beispiel #18
0
 public void setValueStatement(
     PreparedStatement statement, int indiceParametro, BigDecimal valore, int sqlType)
     throws SystemError {
   try {
     if (valore == null) statement.setNull(indiceParametro, sqlType);
     else statement.setBigDecimal(indiceParametro, valore);
   } catch (SQLException ex) {
     throw new SystemError(ex.toString(), MODULO, "setValueStatement", ex);
   }
 }
  public void nullSafeSet(PreparedStatement statement, Object value, int index)
      throws HibernateException, SQLException {

    if (value == null) {
      statement.setNull(index, Types.NUMERIC);
    } else {
      MonetaryAmount anyCurrency = (MonetaryAmount) value;
      MonetaryAmount amountInUSD = MonetaryAmount.convert(anyCurrency, Currency.getInstance("USD"));
      statement.setBigDecimal(index, amountInUSD.getValue());
    }
  }
 public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
   String methodCall = "setBigDecimal(" + parameterIndex + ", " + x + ")";
   argTraceSet(parameterIndex, "(BigDecimal)", x);
   try {
     realPreparedStatement.setBigDecimal(parameterIndex, x);
   } catch (SQLException s) {
     reportException(methodCall, s);
     throw s;
   }
   reportReturn(methodCall);
 }
Beispiel #21
0
  private PreparedStatement buildStatement(
      Scenario scenario,
      List<Column> columns,
      PreparedStatement statement,
      SimpleDateFormat simpleDateFormat)
      throws Exception {
    int count = 1;
    for (Column column : columns) {

      DataValue dataValue = getRulesApplier().getDataForRule(scenario, column);
      switch (column.getType()) {
        case VARCHAR:
          if (dataValue.getValue().equals("")) {
            statement.setNull(count, Types.VARCHAR);
          } else {
            statement.setString(count, dataValue.getValue());
          }
          break;
        case CHAR:
          if (dataValue.getValue().equals("")) {
            statement.setNull(count, Types.CHAR);
          } else {
            statement.setString(count, dataValue.getValue());
          }
          break;
        case DECIMAL:
          if (dataValue.getValue().equals("")) {
            statement.setNull(count, Types.DECIMAL);
          } else {
            statement.setBigDecimal(count, new BigDecimal(dataValue.getValue()));
          }
          break;
        case INTEGER:
          if (dataValue.getValue().equals("")) {
            statement.setNull(count, Types.INTEGER);
          } else {
            statement.setInt(count, Integer.parseInt(dataValue.getValue()));
          }
          break;
        case DATE:
          if (dataValue.getValue().equals("")) {
            statement.setNull(count, Types.DATE);
          } else {
            Date date = new java.sql.Date(simpleDateFormat.parse(dataValue.getValue()).getTime());
            statement.setDate(count, date);
          }
          break;
        default:
          break;
      }
      count++;
    }
    return statement;
  }
 private static void mapObject(PreparedStatement pstm, int index, Object arg) throws SQLException {
   Class<?> argClass = arg.getClass();
   if (argClass == String.class) pstm.setString(index, (String) arg);
   else if (argClass == Integer.class) pstm.setInt(index, (Integer) arg);
   else if (argClass == BigDecimal.class) pstm.setBigDecimal(index, (BigDecimal) arg);
   else if (argClass == Date.class)
     pstm.setTimestamp(index, new Timestamp(((Date) arg).getTime()));
   else if (argClass == Long.class) pstm.setLong(index, (Long) arg);
   else if (argClass == Double.class) pstm.setDouble(index, (Double) arg);
   else if (argClass == Float.class) pstm.setFloat(index, (Float) arg);
 }
 public boolean transfer(
     int nColumnNumber1Based, ResultSet resultSetSource, PreparedStatement insertStatementInsert) {
   try {
     BigDecimal value = resultSetSource.getBigDecimal(m_nColSourceIndex);
     if (!resultSetSource.wasNull()) insertStatementInsert.setBigDecimal(m_nColSourceIndex, value);
     else insertStatementInsert.setNull(m_nColSourceIndex, Types.DECIMAL);
     return true;
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return false;
 }
 public void simpanProduk(Produk p) throws SQLException {
   Connection c = dataSource.getConnection();
   String sqlSimpan =
       "INSERT INTO `produk`(`kodeProduk`, `nama`, `harga`, `terakhirUpdate`) VALUES (?,?,?,?)";
   PreparedStatement psSimpan = c.prepareStatement(sqlSimpan);
   psSimpan.setString(1, p.getKodeProduk());
   psSimpan.setString(2, p.getNama());
   psSimpan.setBigDecimal(3, p.getHarga());
   psSimpan.setDate(4, new java.sql.Date(p.getTerakhirUpdate().getTime()));
   psSimpan.executeUpdate();
   c.close();
 }
 private void InsertBuget() throws SQLException {
   ExtragereDate();
   String insertOfBuget =
       "Insert into buget (denumire, valoare, data_inceput, data_sfarsit, detalii_buget)"
           + "value (?,?,?,?,?)";
   ps = connected.prepareStatement(insertOfBuget);
   ps.setInt(1, VenitNou.getTip());
   ps.setBigDecimal(2, VenitNou.getValoare());
   ps.setString(3, VenitNou.getData_inceput());
   ps.setString(4, VenitNou.getData_sfarsit());
   ps.setString(5, VenitNou.getDetalii());
   ps.executeUpdate();
 }
 public RewardConfirmation confirmReward(AccountContribution contribution, Dining dining) {
   String sql =
       "insert into T_REWARD (CONFIRMATION_NUMBER, REWARD_AMOUNT, REWARD_DATE, ACCOUNT_NUMBER, DINING_MERCHANT_NUMBER, DINING_DATE, DINING_AMOUNT) values (?, ?, ?, ?, ?, ?, ?)";
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = dataSource.getConnection();
     ps = conn.prepareStatement(sql);
     String confirmationNumber = nextConfirmationNumber();
     ps.setString(1, confirmationNumber);
     ps.setBigDecimal(2, contribution.getAmount().asBigDecimal());
     ps.setDate(3, new Date(SimpleDate.today().inMilliseconds()));
     ps.setString(4, contribution.getAccountNumber());
     ps.setString(5, dining.getMerchantNumber());
     ps.setDate(6, new Date(dining.getDate().inMilliseconds()));
     ps.setBigDecimal(7, dining.getAmount().asBigDecimal());
     ps.execute();
     return new RewardConfirmation(confirmationNumber, contribution);
   } catch (SQLException e) {
     throw new RuntimeException("SQL exception occured inserting reward record", e);
   } finally {
     if (ps != null) {
       try {
         // Close to prevent database cursor exhaustion
         ps.close();
       } catch (SQLException ex) {
       }
     }
     if (conn != null) {
       try {
         // Close to prevent database connection exhaustion
         conn.close();
       } catch (SQLException ex) {
       }
     }
   }
 }
Beispiel #27
0
 private static void nuevo() {
   Articulo articulo = scanArticulo();
   // showArticulo(articulo);
   try {
     if (insertPreparedStatement == null)
       insertPreparedStatement = connection.prepareStatement(insertSql);
     insertPreparedStatement.setString(1, articulo.nombre);
     insertPreparedStatement.setLong(2, articulo.categoria);
     insertPreparedStatement.setBigDecimal(3, articulo.precio);
     insertPreparedStatement.executeUpdate();
     System.out.println("artículo guardado.");
   } catch (SQLException ex) {
     showSQLException(ex);
   }
 }
 private void doInsert(BigDecimal digiObjId, String mimeType, byte[] contents)
     throws SQLException {
   Connection conn = source.getConnection();
   PreparedStatement pstmt =
       conn.prepareStatement(
           "insert into THUMBNAILS (DIGOBJEKTID, MIME, CONTENTS) values (?, ?, ?)");
   try {
     pstmt.setBigDecimal(1, digiObjId);
     pstmt.setString(2, mimeType);
     pstmt.setBytes(3, contents);
     pstmt.executeUpdate();
   } finally {
     SQLQuery.tryClose(pstmt);
   }
 }
Beispiel #29
0
  public void saveServicePrice(ServicePrice servicePrice) {
    try {
      PreparedStatement preparedStatement =
          getConnection()
              .prepareStatement(
                  "INSERT INTO \"service_price\" (\"service_id\", \"date\", \"price\") VALUES(?, ?, ?)");
      preparedStatement.setInt(1, servicePrice.getServiceId());
      preparedStatement.setDate(2, Date.valueOf(servicePrice.getDate()));
      preparedStatement.setBigDecimal(3, servicePrice.getPrice());
      preparedStatement.executeUpdate();

    } catch (SQLException ex) {
      ex.printStackTrace();
      throw new DAOException();
    }
  }
Beispiel #30
0
 /**
  * Deletes the instance of the data element. The store method needs to guarantee that the data
  * object is of type Name.
  *
  * @param name the instance to delete. @ if there is a problem deleting.
  */
 protected void delete(Committee committee) {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = getDataSource().getConnection();
     ps = conn.prepareStatement(DELETE_QUERY);
     ps.setString(1, committee.getPersonId());
     ps.setBigDecimal(2, committee.getEntryId());
     int result = ps.executeUpdate();
     logService.debug("There were " + result + " rows deleted.");
   } catch (SQLException sqle) {
     throw new DataAccessException(sqle);
   } finally {
     close(conn, ps, null);
   }
 }