List of usage examples for java.sql ResultSet getFloat
float getFloat(String columnLabel) throws SQLException;
ResultSet
object as a float
in the Java programming language. From source file:com.icsshs.datatransfer.database.impl.QueryBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>/*from ww w. j a va2s.c o m*/ * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(byte[].class)) { return rs.getBytes(index); } else { return rs.getObject(index); } }
From source file:com.alibaba.wasp.jdbc.TestJdbcResultSet.java
@Test public void testStoringQuery() throws SQLException, IOException { trace("testStoringQuery"); ResultSet rs; stat = conn.createStatement();/*from w w w . j a v a 2 s . co m*/ stat.execute("INSERT INTO test (column1,column2,column3,column4) VALUES (1, 72001, 'testStoringQuery', 1)"); rs = stat.executeQuery("SELECT column4 FROM test where column4=1"); assertTrue(rs.next()); assertTrue(rs.getFloat("column4") == 1); }
From source file:io.github.vteial.maxmoney.jdbc.CustomerRowMapper.java
@Override public Customer mapRow(ResultSet resultSet, int intRow) throws SQLException { Customer model = new Customer(); model.setCustomerCode(resultSet.getString("customer_code")); model.setCustomerName(resultSet.getString("customer_name")); model.setAddress(resultSet.getString("address")); model.setTown(resultSet.getString("town")); model.setCountry(resultSet.getString("country")); model.setPostalCode(resultSet.getString("postal_code")); model.setPhone1(resultSet.getString("phone1")); model.setPhone2(resultSet.getString("phone2")); model.setFax(resultSet.getString("fax")); model.setHandPhone(resultSet.getString("hand_phone")); model.setEmail(resultSet.getString("email")); model.setCustomerType(resultSet.getString("customer_type")); model.setAccountNo(resultSet.getString("account_no")); model.setBnLicenseNo(resultSet.getString("bn_license_no")); model.setLicenseExpiryDate(resultSet.getDate("license_expiry_date")); model.setBranchType(resultSet.getString("branch_type")); model.setStatus(resultSet.getString("status")); model.setPriority(resultSet.getInt("priority")); model.setCustomerLocation(resultSet.getString("customer_location")); model.setBaseCurrency(resultSet.getString("base_currency")); model.setLastBalance(resultSet.getFloat("last_balance")); model.setCreateUser(resultSet.getString("create_user")); model.setCreateDate(resultSet.getDate("create_date")); model.setCreateTime(resultSet.getDate("create_time")); model.setUpdateUser(resultSet.getString("update_user")); model.setUpdateDate(resultSet.getDate("update_date")); model.setUpdateTime(resultSet.getDate("update_time")); return model; }
From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>//ww w . ja va 2s . c om * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(SQLXML.class)) { return rs.getSQLXML(index); } else { return rs.getObject(index); } }
From source file:org.liveSense.api.beanprocessors.DbStandardBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * /*from w ww . j av a 2 s .com*/ * <p> * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return (rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return (rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return (rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return (rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return (rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return (rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return (rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else { return rs.getObject(index); } }
From source file:se.technipelago.weather.chart.Generator.java
private void setArchivedData(Map<String, Object> map) { PreparedStatement stmt = null; ResultSet result = null; init();/*from w ww.j av a 2s . c o m*/ try { stmt = conn.prepareStatement("SELECT * FROM archive WHERE ts = (SELECT MAX(ts) FROM archive)"); result = stmt.executeQuery(); if (result.next()) { map.put("timestamp", result.getTimestamp(2)); map.put("temp_out", result.getFloat(3)); map.put("temp_in", result.getFloat(4)); map.put("hum_out", result.getInt(5)); map.put("hum_in", result.getInt(6)); map.put("dew", calculateDewPoint(result.getFloat(3), result.getInt(5))); map.put("heat_index", calculateHeatIndex(result.getFloat(3), result.getInt(5))); map.put("barometer", result.getFloat(7)); map.put("rain", result.getFloat(8)); map.put("rain_rate", result.getFloat(9)); map.put("wind_avg", result.getFloat(10)); map.put("wind_dir", getDirection(result.getInt(11))); map.put("wind_dir_name", getDirectionName(result.getInt(11))); map.put("wind_high", result.getFloat(12)); map.put("chill", calculateWindChill(result.getFloat(3), result.getFloat(10))); map.put("solar", result.getInt(13)); map.put("uv", result.getFloat(14)); } } catch (SQLException ex) { log.log(Level.SEVERE, null, ex); } finally { if (result != null) { try { result.close(); } catch (SQLException ex) { log.log(Level.WARNING, "Failed to close ResultSet", ex); } } if (stmt != null) { try { stmt.close(); } catch (SQLException ex) { log.log(Level.WARNING, "Failed to close select statement", ex); } } } }
From source file:chh.utils.db.source.common.JdbcClient.java
public List<List<Column>> select(String sqlQuery, List<Column> queryParams) { Connection connection = null; try {// w w w .j av a2 s . c o m connection = connectionProvider.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery); if (queryTimeoutSecs > 0) { preparedStatement.setQueryTimeout(queryTimeoutSecs); } setPreparedStatementParams(preparedStatement, queryParams); ResultSet resultSet = preparedStatement.executeQuery(); List<List<Column>> rows = Lists.newArrayList(); while (resultSet.next()) { ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); List<Column> row = Lists.newArrayList(); for (int i = 1; i <= columnCount; i++) { String columnLabel = metaData.getColumnLabel(i); int columnType = metaData.getColumnType(i); Class columnJavaType = Util.getJavaType(columnType); if (columnJavaType.equals(String.class)) { row.add(new Column<String>(columnLabel, resultSet.getString(columnLabel), columnType)); } else if (columnJavaType.equals(Integer.class)) { row.add(new Column<Integer>(columnLabel, resultSet.getInt(columnLabel), columnType)); } else if (columnJavaType.equals(Double.class)) { row.add(new Column<Double>(columnLabel, resultSet.getDouble(columnLabel), columnType)); } else if (columnJavaType.equals(Float.class)) { row.add(new Column<Float>(columnLabel, resultSet.getFloat(columnLabel), columnType)); } else if (columnJavaType.equals(Short.class)) { row.add(new Column<Short>(columnLabel, resultSet.getShort(columnLabel), columnType)); } else if (columnJavaType.equals(Boolean.class)) { row.add(new Column<Boolean>(columnLabel, resultSet.getBoolean(columnLabel), columnType)); } else if (columnJavaType.equals(byte[].class)) { row.add(new Column<byte[]>(columnLabel, resultSet.getBytes(columnLabel), columnType)); } else if (columnJavaType.equals(Long.class)) { row.add(new Column<Long>(columnLabel, resultSet.getLong(columnLabel), columnType)); } else if (columnJavaType.equals(Date.class)) { row.add(new Column<Date>(columnLabel, resultSet.getDate(columnLabel), columnType)); } else if (columnJavaType.equals(Time.class)) { row.add(new Column<Time>(columnLabel, resultSet.getTime(columnLabel), columnType)); } else if (columnJavaType.equals(Timestamp.class)) { row.add(new Column<Timestamp>(columnLabel, resultSet.getTimestamp(columnLabel), columnType)); } else { throw new RuntimeException( "type = " + columnType + " for column " + columnLabel + " not supported."); } } rows.add(row); } return rows; } catch (SQLException e) { throw new RuntimeException("Failed to execute select query " + sqlQuery, e); } finally { closeConnection(connection); } }
From source file:se.technipelago.weather.chart.Generator.java
private void setCurrentData(Map<String, Object> map) { PreparedStatement stmt = null; ResultSet result = null; init();//from w w w . j a v a 2 s . c om try { stmt = conn.prepareStatement("SELECT * FROM current"); result = stmt.executeQuery(); if (result.next()) { // id (primary key) is column index 1 map.put("bar_trend", result.getInt(2)); map.put("console_battery", result.getFloat(3)); map.put("forecast_icons", result.getString(4)); map.put("forecast_msg", result.getString(5)); map.put("sunrise", result.getTimestamp(6)); map.put("sunset", result.getTimestamp(7)); //map.put("timestamp", result.getTimestamp(8)); map.put("transmit_battery", result.getInt(9)); } else { map.put("bar_trend", 0); map.put("console_battery", 4.5); map.put("forecast_icons", "none"); map.put("forecast_msg", "NO CURRENT VALUES"); map.put("sunrise", new Date()); map.put("sunset", new Date()); } } catch (SQLException ex) { log.log(Level.SEVERE, null, ex); } finally { if (result != null) { try { result.close(); } catch (SQLException ex) { log.log(Level.WARNING, "Failed to close ResultSet", ex); } } if (stmt != null) { try { stmt.close(); } catch (SQLException ex) { log.log(Level.WARNING, "Failed to close select statement", ex); } } } }
From source file:org.jumpmind.db.sql.JdbcSqlTemplate.java
@SuppressWarnings("unchecked") public <T> T getObjectFromResultSet(ResultSet rs, Class<T> clazz) throws SQLException { T result;//from www . ja v a2 s . co m if (Date.class.isAssignableFrom(clazz)) { result = (T) rs.getTimestamp(1); } else if (String.class.isAssignableFrom(clazz)) { result = (T) rs.getString(1); } else if (Long.class.isAssignableFrom(clazz)) { result = (T) new Long(rs.getLong(1)); } else if (Integer.class.isAssignableFrom(clazz)) { result = (T) new Integer(rs.getInt(1)); } else if (Float.class.isAssignableFrom(clazz)) { result = (T) new Float(rs.getFloat(1)); } else if (Double.class.isAssignableFrom(clazz)) { result = (T) new Double(rs.getDouble(1)); } else if (BigDecimal.class.isAssignableFrom(clazz)) { result = (T) rs.getBigDecimal(1); } else { result = (T) rs.getObject(1); } return result; }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.data.DBWriter.java
/** Get the cumulative payoffs of the given subject in the given session */ public float getCumulativePayoff(int sessionId, int subjectId, SubjectDef subjectDef) { Connection conn = null;//from w ww . jav a 2s. c o m Object[] results = null; try { conn = dbc.getConnection(); int subjectId_db = subjectDef.getDatabaseId(subjectId); String query = "select sum(payoff) from subject_payoffs where subject_id=" + subjectId_db + " and session_id=" + sessionId; results = dbc.executeQuery(query, conn); ResultSet rs = (ResultSet) results[0]; rs.next(); return rs.getFloat(1); } catch (SQLException e) { log.error("Failed to get the cumulative payoffs of subject " + subjectId, e); } finally { dbc.closeQuery(conn); } return 0f; }