Java Code Examples for java.sql.ResultSet.getDouble()

The following are Jave code examples for showing how to use getDouble() of the java.sql.ResultSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: SistemaAlmoxarifado   File: EmpenhoDAO.java   View Source Code Vote up 7 votes
public static Empenho retreave(int id) throws SQLException {
    Statement stm
            = Database.createConnection().
                    createStatement();
    String sql = "SELECT * FROM empenhos where id = " + id;
    ResultSet rs = stm.executeQuery(sql);
    rs.next();
    ArrayList<EmpenhoItem> itens = EmpenhoItemDAO.retreaveByEmpenho(id);
    return new Empenho(id,
            FornecedorDAO.retreave(rs.getInt("fornecedor")),
            rs.getTimestamp("emissao"),
            rs.getString("numero"),
            rs.getString("observacao"),
            rs.getDouble("valor_total"),
            itens);

}
 
Example 2
Project: SistemaAlmoxarifado   File: ProdutoDAO.java   View Source Code Vote up 6 votes
public static Produto retreave(int id) throws SQLException {
    Statement stm
            = Database.createConnection().
                    createStatement();
    String sql = "SELECT * FROM produtos where id = " + id;
    ResultSet rs = stm.executeQuery(sql);
    rs.next();
    Unidade un = UnidadeDAO.retreave(rs.getInt("unidade"));
    return new Produto(id,
            rs.getString("descricao"),
            un,
            rs.getDouble("estoque"),
            rs.getDouble("valor_total"),
            rs.getDouble("estoque_minimo"));

}
 
Example 3
Project: pub-service   File: MySqlColumnMapRowMapper.java   View Source Code Vote up 6 votes
@Override
public Map<String, Object>  mapRow(ResultSet rs, int rowNum) throws SQLException {
	ResultSetMetaData rsmd = rs.getMetaData();
	int columnCount = rsmd.getColumnCount();
	Map mapOfColValues = createColumnMap(columnCount);
	for (int i = 1; i <= columnCount; i++) {
		String key = getColumnKey(JdbcUtils.lookupColumnName(rsmd, i));
		key = key.toLowerCase();
		Object obj = null;
		String typename= rsmd.getColumnTypeName(i).toUpperCase();
		if("DECIMAL".equals(typename)){
			obj = rs.getDouble(i);
		}else{
			obj = getColumnValue(rs, i);
		}
		 
		mapOfColValues.put(key, obj);
	}
	return mapOfColValues;
}
 
Example 4
Project: scorekeeperfrontend   File: Run.java   View Source Code Vote up 5 votes
/**
 * Extract run data from a SQL result set
 * @param rs the result set pointed at the row in question
 * @throws SQLException if an error occurs extracting run data
 */
public Run(ResultSet rs) throws SQLException
{
	super(rs);
	eventid = (UUID)rs.getObject("eventid");
	carid   = (UUID)rs.getObject("carid");
	course  = rs.getInt("course");
	run     = rs.getInt("run");
	cones   = rs.getInt("cones");
	gates   = rs.getInt("gates");
	status  = rs.getString("status");
	raw     = rs.getDouble("raw");
}
 
Example 5
Project: lams   File: ToolDBUpdater.java   View Source Code Vote up 5 votes
/**
    * Activates/de-activates tool in db based on the flag
    * 
    * @param toolSig
    *            The signature of the tool to activate/de-activate
    * @param flag
    *            Set to 1 for activate, 0 for de-activate
    * @throws SQLException
    */
   public void activateTool(String toolSig, int flag) throws SQLException {
Connection conn = getConnection();
PreparedStatement stmt = null;
ResultSet results = null;
try {
    stmt = conn.prepareStatement(
	    "UPDATE lams_tool SET valid_flag = " + flag + " WHERE tool_signature  = \"" + toolSig + "\"");
    stmt.execute();

    stmt = conn.prepareStatement(
	    "SELECT learning_library_id FROM lams_tool WHERE tool_signature=\"" + toolSignature + "\"");
    results = stmt.executeQuery();

    if (results.first()) {
	double llid = results.getDouble("learning_library_id");

	stmt = conn.prepareStatement("UPDATE lams_learning_library SET valid_flag = " + flag
		+ " WHERE learning_library_id  = \"" + llid + "\"");
	stmt.execute();
    }
} catch (SQLException se) {
    throw new DeployException("Could not activate/de-activate tool for update");
} finally {
    DbUtils.closeQuietly(stmt);
}
   }
 
Example 6
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 5 votes
public Object getResult(ResultSet rs, String columnName) throws SQLException {

            double d = rs.getDouble(columnName);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return new Double(d);
            }
        }
 
Example 7
Project: mcClans   File: DatabaseLoader.java   View Source Code Vote up 5 votes
@Override
protected void loadClans() {
    ResultSet clansResultSet = databaseConnectionOwner.executeQuery(GET_CLANS_QUERY);
    if (clansResultSet != null) {
        try {
            while (clansResultSet.next()) {
                int clanID = clansResultSet.getInt("clan_id");
                String clanTag = clansResultSet.getString("clantag");
                String clanName = clansResultSet.getString("clanname");
                int ownerID = clansResultSet.getInt("clanplayer_id_owner");
                String tagColorId = clansResultSet.getString("tagcolor");
                boolean allowAllyInvites = clansResultSet.getBoolean("allow_ally_invites");
                boolean ffProtection = clansResultSet.getBoolean("ff_protection");
                long creationTime = clansResultSet.getLong("creation_time");

                String homeWorld = clansResultSet.getString("clanhome_world");
                double homeX = clansResultSet.getDouble("clanhome_x");
                double homeY = clansResultSet.getDouble("clanhome_y");
                double homeZ = clansResultSet.getDouble("clanhome_z");
                float homeYaw = clansResultSet.getFloat("clanhome_yaw");
                float homePitch = clansResultSet.getFloat("clanhome_pitch");

                int homeSetTimes = clansResultSet.getInt("clanhome_set_times");
                long homeLastSetTimeStamp = clansResultSet.getLong("clanhome_set_timestamp");

                String bankId = clansResultSet.getString("bank_id");

                super.loadedClan(clanID, clanTag, clanName, ownerID, tagColorId, allowAllyInvites, ffProtection, creationTime, homeWorld, homeX,
                        homeY, homeZ, homeYaw, homePitch, homeSetTimes, homeLastSetTimeStamp, bankId);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
 
Example 8
Project: SistemaAlmoxarifado   File: SaidaProdutoDAO.java   View Source Code Vote up 5 votes
public static SaidaProduto retreave(int id) throws SQLException {
    Statement stm
            = Database.createConnection().
                    createStatement();
    String sql = "SELECT * FROM saidas_produtos where id = " + id;
    ResultSet rs = stm.executeQuery(sql);
    rs.next();
    return new SaidaProduto(id,
            RequisicaoProdutoDAO.retreave(rs.getInt("produto_requisicao")),
            rs.getDouble("quantidade"),
            rs.getTimestamp("data"));
}
 
Example 9
Project: SistemaAlmoxarifado   File: EntradaItemDAO.java   View Source Code Vote up 5 votes
public static EntradaItem retreave(int id) throws SQLException {
    Statement stm
            = Database.createConnection().
                    createStatement();
    String sql = "SELECT * FROM entrada_itens where id = " + id;
    ResultSet rs = stm.executeQuery(sql);
    rs.next();
    return new EntradaItem(id,
            ProdutoDAO.retreave(rs.getInt("produto")),
            rs.getInt("entrada"),
            rs.getDouble("quantidade"),
            rs.getTimestamp("validade"),
            rs.getString("lote"),
            rs.getDouble("valor_unitario"));
}
 
Example 10
Project: aliyun-maxcompute-data-collectors   File: JdbcWritableBridge.java   View Source Code Vote up 5 votes
public static Double readDouble(int colNum, ResultSet r) throws SQLException {
  double val;
  val = r.getDouble(colNum);
  if (r.wasNull()) {
    return null;
  } else {
    return Double.valueOf(val);
  }
}
 
Example 11
Project: sample.daytrader3   File: TradeDirect.java   View Source Code Vote up 5 votes
private HoldingDataBean getHoldingDataFromResultSet(ResultSet rs)
		throws Exception {
	HoldingDataBean holdingData = null;

	holdingData = new HoldingDataBean(new Integer(rs.getInt("holdingID")),
			rs.getDouble("quantity"), rs.getBigDecimal("purchasePrice"), rs
					.getTimestamp("purchaseDate"), rs
					.getString("quote_symbol"));
	return holdingData;
}
 
Example 12
Project: scorekeeperfrontend   File: ChallengeRound.java   View Source Code Vote up 5 votes
public ChallengeRound(ResultSet rs) throws SQLException
{
	challengeid  = (UUID)rs.getObject("challengeid");
	round        = rs.getInt("round");
	car1         = new ChallengeRound.RoundEntrant();
	car1.carid   = (UUID)rs.getObject("car1id");
	car1.dial    = rs.getDouble("car1dial");
	car2         = new ChallengeRound.RoundEntrant();
	car2.carid   = (UUID)rs.getObject("car2id");
	car2.dial    = rs.getDouble("car2dial");
}
 
Example 13
Project: uroborosql   File: OptionalDoublePropertyMapper.java   View Source Code Vote up 5 votes
@Override
public OptionalDouble getValue(final JavaType type, final ResultSet rs, final int columnIndex,
		final PropertyMapperManager mapperManager)
		throws SQLException {
	double value = rs.getDouble(columnIndex);
	if (!rs.wasNull()) {
		return OptionalDouble.of(value);
	} else {
		return OptionalDouble.empty();
	}
}
 
Example 14
Project: scorekeeperfrontend   File: Payment.java   View Source Code Vote up 5 votes
public Payment(ResultSet rs) throws SQLException
{
    payid    = (UUID)rs.getObject("payid");
    eventid  = (UUID)rs.getObject("eventid");
    carid    = (UUID)rs.getObject("carid");
    refid    = rs.getString("refid");
    txtype   = rs.getString("txtype");
    txid     = rs.getString("txid");
    txtime   = rs.getTimestamp("txtime", Database.utc);
    itemname = rs.getString("itemname");
    amount   = rs.getDouble("amount");
}
 
Example 15
Project: DBus   File: FloatSplitter.java   View Source Code Vote up 5 votes
public List<InputSplit> split(long numSplits, ResultSet results,
    String colName, DBConfiguration dbConf) throws SQLException {

  LOG.warn("Generating splits for a floating-point index column. Due to the");
  LOG.warn("imprecise representation of floating-point values in Java, this");
  LOG.warn("may result in an incomplete import.");
  LOG.warn("You are strongly encouraged to choose an integral split column.");

  List<InputSplit> splits = new ArrayList<InputSplit>();

  if (results.getString(1) == null && results.getString(2) == null) {
    // Range is null to null. Return a null split accordingly.
    splits.add(new DataDrivenDBInputFormat.DataDrivenDBInputSplit(
            type, colName, DataPullConstants.QUERY_COND_IS_NULL, null, DataPullConstants.QUERY_COND_IS_NULL, null));
    return splits;
  }

  double minVal = results.getDouble(1);
  double maxVal = results.getDouble(2);

  // Use this as a hint. May need an extra task if the size doesn't
  // divide cleanly.
  double splitSize = (maxVal - minVal) / (double) numSplits;

  if (splitSize < MIN_INCREMENT) {
    splitSize = MIN_INCREMENT;
  }

  double curLower = minVal;
  double curUpper = curLower + splitSize;

  while (curUpper < maxVal) {
    splits.add(new DataDrivenDBInputFormat.DataDrivenDBInputSplit(
            type, colName, " >= ", curLower, " < ", curUpper));

    curLower = curUpper;
    curUpper += splitSize;
  }

  // Catch any overage and create the closed interval for the last split.
  if (curLower <= maxVal || splits.size() == 1) {
    splits.add(new DataDrivenDBInputFormat.DataDrivenDBInputSplit(
            type, colName, " >= ", curUpper, " <= ", maxVal));
  }

  if (results.getString(1) == null || results.getString(2) == null) {
    // At least one extrema is null; add a null split.
    splits.add(new DataDrivenDBInputFormat.DataDrivenDBInputSplit(
            type, colName, DataPullConstants.QUERY_COND_IS_NULL, null, DataPullConstants.QUERY_COND_IS_NULL, null));
  }

  return splits;
}
 
Example 16
Project: scorekeeperfrontend   File: Entrant.java   View Source Code Vote up 5 votes
public Entrant(ResultSet rs) throws SQLException
{
    this();
    car       = new Car(rs);
    driverid  = (UUID)rs.getObject("driverid");
    firstname = rs.getString("firstname");
    lastname  = rs.getString("lastname");
    try {
        paid  = rs.getDouble("paid");
    } catch (SQLException pse) {
    }
}
 
Example 17
Project: spring2017java   File: FXMLDocumentController.java   View Source Code Vote up 5 votes
@Override
public void initialize(URL url, ResourceBundle rb) {
    studentsList = FXCollections.observableArrayList();
    studentsListView.setItems(studentsList);
    studentsTableView.setItems(studentsList);
    
    // lambda expression
    nameColumn.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getStudentName()));
    idColumn.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getStudentId()));
    cgpaColumn.setCellValueFactory(data -> new SimpleDoubleProperty(data.getValue().getCgpa()));
    
    try {
        Connection connection = DriverManager
                .getConnection("jdbc:mysql://172.17.0.119/spring2017db",
                        "javauser",
                        "java");
        Statement statement = connection.createStatement();
        String query = "SELECT * FROM student";

        ResultSet resultSet = statement.executeQuery(query);
        int rows = 0;
        while (resultSet.next()) {
            int id = resultSet.getInt("studentId");
            String name = resultSet.getString("studentName");
            double cgpa = resultSet.getDouble("cgpa");
            Student student = new Student(id, name, cgpa);
            studentsList.add(student);
            rows++;
        }
        statusLabel.setText("Successfully loaded " + rows + " records from the database");
    } catch (SQLException sqle) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Error Message");
        alert.setContentText("Could not connect to the database");
        alert.showAndWait();
        System.exit(0);
        System.err.println("Could not connect to the database");
    }
}
 
Example 18
Project: aliyun-maxcompute-data-collectors   File: OracleConnectionFactoryTest.java   View Source Code Vote up 4 votes
private void setAndCheckJdbcFetchSize(int jdbcFetchSize) {

    try {
      Connection conn = getConnection();

      String uniqueJunk =
          (new SimpleDateFormat("yyyyMMddHHmmsszzz")).format(new Date())
              + jdbcFetchSize;

      org.apache.hadoop.conf.Configuration conf = new Configuration();
      conf.setInt(OraOopConstants.ORACLE_ROW_FETCH_SIZE, jdbcFetchSize);

      // Prevent setJdbcFetchSize() from logging information about the
      // fetch-size
      // changing. Otherwise, the junit output will be polluted with messages
      // about
      // things that aren't actually a problem...
      boolean logIsBeingCached =
          OracleConnectionFactory.LOG.getCacheLogEntries();
      OracleConnectionFactory.LOG.setCacheLogEntries(true);

      OraOopOracleQueries.setJdbcFetchSize(conn, conf);

      OracleConnectionFactory.LOG.setCacheLogEntries(logIsBeingCached);

      String uniqueSql =
          String.format("select /*%s*/ * from dba_objects", uniqueJunk);
      // Usually dba_objects will have a lot of rows
      ResultSet resultSet1 = conn.createStatement().executeQuery(uniqueSql);
      while (resultSet1.next()) {
        // Nothing to do
        continue;
      }

      ResultSet resultSet2 =
          conn.createStatement().executeQuery(OraOopTestConstants.SQL_TABLE);
      boolean sqlFound = false;
      double rowsPerFetch = 0;
      while (resultSet2.next()) {
        String sqlText = resultSet2.getString("SQL_TEXT");
        if (sqlText.contains(uniqueJunk)) {
          sqlFound = true;
          rowsPerFetch = resultSet2.getDouble("ROWS_PER_FETCH");
          break;
        }
      }

      if (!sqlFound) {
        Assert
            .fail("Unable to find the performance metrics for the SQL "
                + "statement being used to check the JDBC fetch size.");
      }

      if (rowsPerFetch < jdbcFetchSize * 0.95
          || rowsPerFetch > jdbcFetchSize * 1.05) {
        Assert
            .fail(String
                .format(
                    "The measured JDBC fetch size is not within 5%% of what we "
                    + "expected. Expected=%s rows/fetch, actual=%s rows/fetch",
                    jdbcFetchSize, rowsPerFetch));
      }

    } catch (SQLException ex) {
      Assert.fail(ex.getMessage());
    }
  }
 
Example 19
Project: ralasafe   File: ResultSetReader.java   View Source Code Vote up 4 votes
public Object reader(ResultSet rs, int columnIndex) throws SQLException {
	return new Double(rs.getDouble(columnIndex));
}
 
Example 20
Project: morpheus-core   File: SQLExtractor.java   View Source Code Vote up 4 votes
@Override
@SuppressWarnings("unchecked")
public <V> V getValue(ResultSet rs, int colIndex) throws SQLException {
    final double value = rs.getDouble(colIndex);
    return rs.wasNull() ? null : (V)new Double(value);
}