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:wzw.sql.ResultSetConverter.java
/** * ?/*from w ww .j a v a 2 s .c o m*/ * @param rs * @param type Listjava.sql.Types * @return * @throws SQLException */ public static Object toType(ResultSet rs, int type) throws SQLException { if (rs.next()) { // run rs.next() switch (type) { case Types.INTEGER: return new Integer(rs.getInt(1)); case Types.BIGINT: return new Long(rs.getLong(1)); case Types.VARCHAR: return rs.getString(1); case Types.FLOAT: return new Float(rs.getFloat(1)); case Types.DECIMAL: case Types.DOUBLE: case Types.NUMERIC: return new Double(rs.getDouble(1)); case Types.TIMESTAMP: return rs.getTimestamp(1); case Types.DATE: return rs.getDate(1); case Types.TIME: return rs.getTime(1); default: return null; } } return null; }
From source file:com.tfm.utad.sqoopdata.SqoopVerticaDB.java
private static void findBetweenMinIDAndMaxID(Connection conn, Long minID, Long maxID) { Statement stmt = null;/*w w w . jav a 2s. c o m*/ String query; try { stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); query = "SELECT * FROM s1.coordinates WHERE id > " + minID + " AND id <= " + maxID + ""; LOG.info("Query execution: " + query); ResultSet rs = stmt.executeQuery(query); int batch = 0; List<CoordinateCartoDB> result = new ArrayList<>(); long start_time = System.currentTimeMillis(); while (rs.next()) { batch++; CoordinateCartoDB cdb = new CoordinateCartoDB((long) rs.getInt("id"), rs.getString("userstr"), rs.getString("created_date"), rs.getString("activity"), rs.getFloat("latitude"), rs.getFloat("longitude"), (long) rs.getInt("userid")); result.add(cdb); if (batch == 50) { sendDataToCartoDB(result); batch = 0; result = new ArrayList<>(); } } if (batch > 0) { sendDataToCartoDB(result); } long end_time = System.currentTimeMillis(); long difference = end_time - start_time; LOG.info("CartoDB API execution time: " + String.format("%d min %d sec", TimeUnit.MILLISECONDS.toMinutes(difference), TimeUnit.MILLISECONDS.toSeconds(difference) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(difference)))); } catch (SQLException e) { LOG.error("SQLException error: " + e.toString()); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException ex) { LOG.error("Statement error: " + ex.toString()); } } if (conn != null) { try { conn.close(); } catch (SQLException ex) { LOG.error("Connection error: " + ex.toString()); } } } }
From source file:org.mapbuilderfreq.FrequencyMapClient.java
public static List<MsgData> getMapDataForDate(Date mapDate, String scoreType, float scoreThreshold, boolean onlyQualified) { List<MsgData> msgList = new ArrayList<>(); //mapDate = DateUtils.addDays(mapDate, 1-NUM_DAYS_AGGREGATE);// add -(NUM_DAYS_AGGREGATE-1) days for (int i = 0; i < NUM_DAYS_AGGREGATE; i++) { List<MsgData> tempList = new ArrayList<>(); String lowerDate = DateFormatUtils.format(mapDate, "yyyy-MM-dd"); String upperDate = DateFormatUtils.format(DateUtils.addDays(mapDate, 1), "yyyy-MM-dd"); mapDate = DateUtils.addDays(mapDate, -1); float coefficient = (1 - (i * AGGREGATE_COEFFICIENT)); try {//ww w . jav a2 s .c o m String mapQuery = "SELECT \"Id\", \"Longitude\", \"Latitude\",\"PlacePolygon\",\"UserLocation\", \"NormalizedScore\", \"TagScore\", \"CombinedScore\" " + "FROM public.\"ScoredMsg\" WHERE \"CreatedTime\" < '" + upperDate + "' AND \"CreatedTime\" >= '" + lowerDate + "' "; String scoreClause = ""; switch (scoreType) { case "normal": scoreClause = "AND \"NormalizedScore\" >= " + scoreThreshold; break; case "tag": scoreClause = "AND \"TagScore\" >= " + scoreThreshold; break; case "combined": scoreClause = "AND \"CombinedScore\" >= " + scoreThreshold; break; } mapQuery = mapQuery + scoreClause; if (onlyQualified) { mapQuery = mapQuery + " AND \"IsQualified\" = true"; } mapQuery = mapQuery + ";"; Statement st = db.createStatement(); ResultSet rs = st.executeQuery(mapQuery); while (rs.next()) { MsgData d = new MsgData(); d.setMsgId(rs.getInt(1)); d.setLongitude(rs.getFloat(2)); d.setLatitude(rs.getFloat(3)); d.setPlacePolygon(rs.getString(4)); d.setUserLocation(rs.getString(5)); d.setNormalizedScore(rs.getFloat(6)); d.setTagScore(rs.getFloat(7)); d.setCombinedScore(rs.getFloat(8)); if (d.getNormalizedScore() <= 0) { d.setNormalizedScore(d.getNormalizedScore() * coefficient); } if (d.getTagScore() <= 0) { d.setTagScore(d.getTagScore() * coefficient); } if (d.getCombinedScore() <= 0) { d.setCombinedScore(d.getCombinedScore() * coefficient); } tempList.add(d); } } catch (SQLException ex) { System.err.println("Map Query failed...."); System.err.println(ex); System.exit(0); } msgList.addAll(tempList); } return msgList; }
From source file:wzw.sql.ResultSetConverter.java
/** * ?//from w w w .j a va 2s .c om * @param rs * @param type Listjava.sql.Types * @return * @throws SQLException */ public static List<Object> toTypeList(ResultSet rs, int type) throws SQLException { List<Object> list = new ArrayList<Object>(); switch (type) { case Types.INTEGER: while (rs.next()) { list.add(new Integer(rs.getInt(1))); } case Types.BIGINT: while (rs.next()) { list.add(new Long(rs.getLong(1))); } case Types.VARCHAR: while (rs.next()) { list.add(rs.getString(1)); } case Types.FLOAT: while (rs.next()) { list.add(new Float(rs.getFloat(1))); } case Types.DECIMAL: case Types.DOUBLE: case Types.NUMERIC: while (rs.next()) { list.add(new Double(rs.getDouble(1))); } case Types.TIMESTAMP: while (rs.next()) { list.add(rs.getTimestamp(1)); } case Types.DATE: while (rs.next()) { list.add(rs.getDate(1)); } case Types.TIME: while (rs.next()) { list.add(rs.getTime(1)); } //default: } return list; }
From source file:org.bml.util.geo.util.geolite.GISData.java
public static GISData fromIp(String ipAddress, PreparedStatement ps) throws UnknownHostException, SQLException { GISData data = new GISData(); ResultSet resultSet = null; try {//from www.ja va2 s .co m ps.clearParameters(); setInetAddress(ps, ipAddress); resultSet = ps.executeQuery(); if (resultSet.next()) { data.startIpNum = resultSet.getLong(1); data.endIpNum = resultSet.getLong(2); data.locId = resultSet.getLong(3); data.country = resultSet.getString(4); data.region = resultSet.getString(5); data.city = resultSet.getString(6); data.postalCode = resultSet.getString(7); data.latitude = resultSet.getFloat(8); data.longitude = resultSet.getFloat(9); data.metroCode = resultSet.getString(10); data.areaCode = resultSet.getString(11); } } catch (SQLException e) { LOG.warn("SQLException caught while obtaining GISData from IP=" + ipAddress); throw e; } finally { DbUtils.closeQuietly(resultSet); } return data; }
From source file:org.bml.util.geo.util.geolite.GISData.java
public static GISData fromIp(String ipAddress, Connection connection) throws UnknownHostException, SQLException { GISData data = new GISData(); PreparedStatement ps = null;//from w w w .j a v a 2s . c om ResultSet resultSet = null; try { ps = connection.prepareStatement(PREPARED_GET_SQL); setInetAddress(ps, ipAddress); resultSet = ps.executeQuery(); if (resultSet.next()) { data.startIpNum = resultSet.getLong(1); data.endIpNum = resultSet.getLong(2); data.locId = resultSet.getLong(3); data.country = resultSet.getString(4); data.region = resultSet.getString(5); data.city = resultSet.getString(6); data.postalCode = resultSet.getString(7); data.latitude = resultSet.getFloat(8); data.longitude = resultSet.getFloat(9); data.metroCode = resultSet.getString(10); data.areaCode = resultSet.getString(11); } } catch (SQLException e) { LOG.warn("SQLException caught while obtaining GISData from IP=" + ipAddress); throw e; } finally { DbUtils.closeQuietly(resultSet); DbUtils.closeQuietly(ps); } return data; }
From source file:org.openmrs.module.chartsearch.api.db.hibernate.HibernateChartSearchDAO.java
private static void setResultsFieldValues(ResultSet rs) throws SQLException { ChartSearchCustomIndexer.setId(rs.getString("id")); ChartSearchCustomIndexer.setObsId(rs.getInt("obs_id")); ChartSearchCustomIndexer.setPersonId(rs.getInt("person_id")); ChartSearchCustomIndexer.setObsDatetime(rs.getDate("obs_datetime")); ChartSearchCustomIndexer.setObsGroupId(rs.getInt("obs_group_id")); ChartSearchCustomIndexer.setConceptName(rs.getString("concept_name")); ChartSearchCustomIndexer.setCoded(rs.getString("coded")); ChartSearchCustomIndexer.setValueDatetime(rs.getDate("value_datetime")); ChartSearchCustomIndexer.setValueNumeric(rs.getFloat("value_numeric")); ChartSearchCustomIndexer.setValueText(rs.getString("value_text")); ChartSearchCustomIndexer.setConceptClassName(rs.getString("concept_class_name")); }
From source file:database.EWPMapper.java
@Override public ExerciseWithParticipants mapRow(ResultSet rs, int rowNum) throws SQLException { ExerciseWithParticipants ewp = new ExerciseWithParticipants(); ewp.setHours(rs.getFloat("exercise.hours")); ewp.setFirstname(rs.getString("users.firstname")); ewp.setLastname(rs.getString("users.lastname")); ewp.setDate(rs.getDate("exercise.date")); return ewp;/*from w w w .ja va 2s . co m*/ }
From source file:com.wabacus.system.datatype.FloatType.java
public Object getColumnValue(ResultSet rs, int iindex, AbsDatabaseType dbtype) throws SQLException { return Float.valueOf(rs.getFloat(iindex)); }
From source file:com.wabacus.system.datatype.FloatType.java
public Object getColumnValue(ResultSet rs, String column, AbsDatabaseType dbtype) throws SQLException { return Float.valueOf(rs.getFloat(column)); }