List of usage examples for java.sql ResultSet getDouble
double getDouble(String columnLabel) throws SQLException;
ResultSet
object as a double
in the Java programming language. From source file:net.chrisrichardson.bankingExample.domain.jdbc.JdbcAccountDao.java
public Account findAccount(String accountId) { logger.debug("finding account"); return (Account) jdbcTemplate.queryForObject("SELECT * FROM BANK_ACCOUNT WHERE accountId = ?", new Object[] { accountId }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { return new Account(rs.getInt("ACCOUNT_ID"), rs.getString("accountId"), rs.getDouble("BALANCE"), rs.getInt("overdraftPolicy"), new Date(rs.getTimestamp("dateOpened").getTime()), rs.getDouble("requiredYearsOpen"), rs.getDouble("limit")); }//w ww . j a v a 2 s.c om }); }
From source file:pl.edu.agh.samm.db.impl.MeasurementValueDAO.java
@Override public Map<String, Number> getAverageMeasurementValue(String resource, Date beforeActionStartTime, Date actionStartTime) {//w w w . ja v a 2s .c om final Map<String, Number> ret = new HashMap<String, Number>(); Map<String, Object> params = new HashMap<String, Object>(); params.put("instance", resource); params.put("start", beforeActionStartTime); params.put("end", actionStartTime); SqlParameterSource sps = new MapSqlParameterSource(params); getSimpleJdbcTemplate().getNamedParameterJdbcOperations().query(SQL_QUERY_AVERAGE_BY_CAPABILITY, sps, new RowCallbackHandler() { @Override public void processRow(ResultSet arg0) throws SQLException { ret.put(arg0.getString(1), arg0.getDouble(2)); } }); return ret; }
From source file:com.carfinance.module.statisticsmanage.domain.VehicleIncomRowMapper.java
public VehicleIncom mapRow(ResultSet rs, int arg1) throws SQLException { VehicleIncom vehicleIncom = new VehicleIncom(); vehicleIncom.setLicense_plate(rs.getString("license_plate")); vehicleIncom.setModel(rs.getString("model")); vehicleIncom.setOver_price(rs.getDouble("over_price")); vehicleIncom.setActually_price(rs.getDouble("actually_price")); return vehicleIncom; }
From source file:org.apache.ctakes.ytex.kernel.InfoContentEvaluatorImpl.java
/** * get the frequency of each term in the corpus. * /* w ww.ja v a 2 s . c o m*/ * @param freqQuery * query returns 2 columns. 1st column - concept id (string), 2nd * column - frequency (double) * @return */ @Override public Map<String, Double> getFrequencies(String freqQuery) { // get the raw frequency final Map<String, Double> rawFreq = new HashMap<String, Double>(); jdbcTemplate.query(freqQuery, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { rawFreq.put(rs.getString(1), rs.getDouble(2)); } }); return rawFreq; }
From source file:com.autentia.tnt.bill.migration.support.MigratedInformationRecoverer.java
/** * Recupera la suma total de todos los conceptos de cada una de las facturas cuyo tipo se envia por parametro * @param billType tipo de factura//from www . java 2 s . co m */ public static double[] getImporteFacturaMigrated(String billType) throws Exception { Connection con = null; PreparedStatement pstmt = null; ResultSet rs = null; LineNumberReader file = null; double[] result = new double[0]; try { log.info("RECOVERING IMPORTE FACTURAS " + billType + " MIGRADAS"); // connect to database Class.forName(BillToBillPaymentMigration.DATABASE_DRIVER); con = DriverManager.getConnection(BillToBillPaymentMigration.DATABASE_CONNECTION, BillToBillPaymentMigration.DATABASE_USER, BillToBillPaymentMigration.DATABASE_PASS); // NOSONAR con.setAutoCommit(false); // DATABASE_PASS vacio String sql = "SELECT bp.amount FROM BillPayment bp, Bill b where bp.billId = b.id and b.billType = ? order by amount"; pstmt = con.prepareStatement(sql); pstmt.setString(1, billType); rs = pstmt.executeQuery(); rs.last(); result = new double[rs.getRow()]; rs.beforeFirst(); int counter = 0; while (rs.next()) { result[counter] = rs.getDouble(1); log.info("\t" + result[counter]); counter++; } } catch (Exception e) { log.error("FAILED: WILL BE ROLLED BACK: ", e); if (con != null) { con.rollback(); } } finally { cierraFichero(file); liberaConexion(con, pstmt, rs); } return result; }
From source file:com.itemanalysis.jmetrik.stats.irt.linking.DbThetaDistribution.java
public DistributionApproximation getDistribution(Connection conn, DataTableName tableName, VariableName thetaName, VariableName weightName, boolean hasWeight) throws SQLException { points = new ArrayList<Double>(); Min min = new Min(); Max max = new Max(); Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery query = new SelectQuery(); query.addColumn(sqlTable, thetaName.nameForDatabase()); if (hasWeight) { query.addColumn(sqlTable, weightName.nameForDatabase()); weights = new ArrayList<Double>(); }//from ww w . j av a2 s .c o m Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery(query.toString()); double value = 0.0; double w = 1.0; while (rs.next()) { value = rs.getDouble(thetaName.nameForDatabase()); if (!rs.wasNull()) { if (hasWeight) { w = rs.getDouble(weightName.nameForDatabase()); if (rs.wasNull()) { w = 0.0; } points.add(value); weights.add(w); min.increment(value); max.increment(value); } else { points.add(value); min.increment(value); max.increment(value); } } } rs.close(); stmt.close(); ContinuousDistributionApproximation dist = new ContinuousDistributionApproximation(points.size(), min.getResult(), max.getResult()); if (hasWeight) { for (int i = 0; i < points.size(); i++) { dist.setPointAt(i, points.get(i)); dist.setDensityAt(i, weights.get(i)); } } else { for (int i = 0; i < points.size(); i++) { dist.setPointAt(i, points.get(i)); } } return dist; }
From source file:com.oltpbenchmark.benchmarks.auctionmark.AuctionMarkProfile.java
private static final void loadConfigProfile(AuctionMarkProfile profile, ResultSet vt) throws SQLException { boolean adv = vt.next(); assert (adv) : String.format("Failed to get data from %s\n%s", AuctionMarkConstants.TABLENAME_CONFIG_PROFILE, vt); int col = 1;/*from w ww . j ava 2 s .c o m*/ profile.scale_factor = vt.getDouble(col++); profile.loaderStartTime = vt.getTimestamp(col++); profile.loaderStopTime = vt.getTimestamp(col++); JSONUtil.fromJSONString(profile.users_per_itemCount, vt.getString(col++)); if (LOG.isDebugEnabled()) LOG.debug(String.format("Loaded %s data", AuctionMarkConstants.TABLENAME_CONFIG_PROFILE)); }
From source file:fitmon.WorkoutData.java
public double calBurned(String date, int userId) throws SQLException { PreparedStatement st = null;/*from w ww.jav a 2 s.c o m*/ Connection conn = null; double calBurned = 0; try { String query = "select date,sum(calories) from Workout where userId=" + userId + " and date='" + date + "'"; Class.forName("com.mysql.jdbc.Driver"); conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/fitmon", "root", "april-23"); st = conn.prepareStatement(query); conn.setAutoCommit(false); ResultSet rs = st.executeQuery(query); while (rs.next()) { calBurned = rs.getDouble("sum(calories)"); } st.close(); conn.close(); } catch (ClassNotFoundException ce) { ce.printStackTrace(); } catch (SQLException se) { se.printStackTrace(); } catch (Exception e) { //Handle errors for Class.forName e.printStackTrace(); } finally { if (st != null) { st.close(); } if (conn != null) { conn.close(); } } return calBurned; }
From source file:e_wallet.TransactionsMapper.java
@Override public Transactions mapRow(ResultSet rs, int rowNum) throws SQLException { Transactions transaction = new Transactions(); transaction.setId(rs.getInt("id")); transaction.setFrom(rs.getString("fromID")); transaction.setTo(rs.getString("toID")); transaction.setAmount(rs.getDouble("amount")); transaction.setStart(rs.getString("start")); transaction.setEnd(rs.getString("end")); transaction.setType(rs.getInt("type")); transaction.setBalance(rs.getDouble("balance")); transaction.setComments(rs.getString("comments")); transaction.setCompletion(rs.getInt("completion")); return transaction; }
From source file:org.aksw.gerbil.database.ExperimentTaskResultRowMapper.java
@Override public ExperimentTaskResult mapRow(ResultSet resultSet, int rowId) throws SQLException { return new ExperimentTaskResult(resultSet.getString(1), resultSet.getString(2), ExperimentType.valueOf(resultSet.getString(3)), Matching.valueOf(resultSet.getString(4)), new double[] { resultSet.getDouble(5), resultSet.getDouble(6), resultSet.getDouble(7), resultSet.getDouble(8), resultSet.getDouble(9), resultSet.getDouble(10) }, resultSet.getInt(11), resultSet.getInt(12), resultSet.getTimestamp(13).getTime()); }