java.sql.ResultSet#getFloat ( )源码实例Demo

下面列出了java.sql.ResultSet#getFloat ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MyBox   文件: TableDoubleMatrix.java
public static float[][] read(String name, int width, int height) {
    float[][] matrix = new float[height][width];
    try ( Connection conn = DriverManager.getConnection(protocol + dbHome() + login)) {
        conn.setReadOnly(true);
        for (int j = 0; j < height; ++j) {
            for (int i = 0; i < width; ++i) {
                String sql = " SELECT * FROM Double_Matrix WHERE name='" + stringValue(name)
                        + "' AND row=" + j + " AND col=" + i;
                ResultSet result = conn.createStatement().executeQuery(sql);
                if (result.next()) {
                    matrix[j][i] = result.getFloat("value");
                }
            }
        }
    } catch (Exception e) {
        failed(e);
        // logger.debug(e.toString());
    }
    return matrix;
}
 
源代码2 项目: TrakEM2   文件: DBLoader.java
private Ball fetchBall(Project project, long id) throws Exception {
	ResultSet r = connection.prepareStatement("SELECT ab_displayables.id, title, ab_displayables.width, height, alpha, visible, color_red, color_green, color_blue, ab_zdisplayables.id, ab_ball_points.ball_id, ab_displayables.locked, m00, m10, m01, m11, m02, m12 FROM ab_zdisplayables, ab_displayables, ab_ball_points WHERE ab_zdisplayables.id=ab_displayables.id AND ab_zdisplayables.id=ab_ball_points.ball_id AND ab_zdisplayables.id=" + id).executeQuery(); // strange query, but can't distinguish between pipes and balls otherwise
	Ball b = null;
	if (r.next()) {
		b = new Ball(project, id, r.getString("title"), (float)r.getDouble("width"), (float)r.getDouble("height"), r.getFloat("alpha"), r.getBoolean("visible"), new Color(r.getInt("color_red"), r.getInt("color_green"), r.getInt("color_blue")), r.getBoolean("locked"), new AffineTransform(r.getDouble("m00"), r.getDouble("m10"), r.getDouble("m01"), r.getDouble("m11"), r.getDouble("m02"), r.getDouble("m12")));
	}
	r.close();
	return b;
}
 
源代码3 项目: spliceengine   文件: AbstractIndexTest.java
protected final void assertColumnDataCorrect(String query,int i, ResultSet rs,boolean expectData) throws SQLException {
    try{
        if(!expectData){
            Assert.assertFalse("Rows returned for query " + query, rs.next());
        }else{
            Assert.assertTrue("No Rows returned for query "+ query,rs.next());

            //validate the correct data returned
            int a = rs.getInt(1);
            Assert.assertFalse("No value for a returned for query a=" + i, rs.wasNull());
            Assert.assertEquals("Incorrect value for a returned for query "+query ,i,a);
            float b = rs.getFloat(2);
            Assert.assertFalse("No value for b returned for query a="+i,rs.wasNull());
            Assert.assertEquals("Incorrect value for b returned for query "+query, 2 * i, b, FLOAT_PRECISION);
            int c = rs.getInt(3);
            Assert.assertFalse("No value for c returned for query a="+i,rs.wasNull());
            Assert.assertEquals("Incorrect value for a returned for query "+query , 3 * i, c);
            double d = rs.getDouble(4);
            Assert.assertFalse("No value for d returned for query a="+i,rs.wasNull());
            Assert.assertEquals("Incorrect value for b returned for query "+query + i, 4 * i, d, DOUBLE_PRECISION);

            Assert.assertFalse("Too many Rows returned for query "+ query,rs.next());
        }
    }finally{
        rs.close();
    }
}
 
源代码4 项目: spliceengine   文件: SortOperationIT.java
@Test
public void testOrderByFloat() throws Exception {
	ResultSet rs = methodWatcher.executeQuery(format("select * from %s order by age",this.getTableReference(TABLE_NAME_2)));
	List<String> returnedByName = new ArrayList<String>();
	while(rs.next()){
		String v = rs.getString(1) + "," + rs.getFloat(2);
		returnedByName.add(v);
	}
	Assert.assertEquals("results are wrong", Arrays.asList("bob,1.2", "joe,5.5", "tom,13.4667"), returnedByName);
}
 
源代码5 项目: gemfirexd-oss   文件: SQLReal.java
/** 
 * @see DataValueDescriptor#setValueFromResultSet 
 *
 * @exception StandardException		Thrown on error
 * @exception SQLException		Thrown on error
 */
public void setValueFromResultSet(ResultSet resultSet, int colNumber,
								  boolean isNullable)
	throws StandardException, SQLException
{
		float fv = resultSet.getFloat(colNumber);
           if (isNullable && resultSet.wasNull())
               restoreToNull();
           else
               setValue(fv);
}
 
源代码6 项目: OpenCue   文件: ActionDaoJdbc.java
public ActionEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
    ActionEntity action = new ActionEntity();
    action.id = rs.getString("pk_action");
    action.showId = rs.getString("pk_show");
    action.filterId = rs.getString("pk_filter");
    action.booleanValue = rs.getBoolean("b_value");
    action.groupValue = rs.getString("pk_folder");
    action.intValue = rs.getLong("int_value");
    action.floatValue = rs.getFloat("float_value");
    action.type = ActionType.valueOf(rs.getString("str_action"));
    action.valueType = ActionValueType.valueOf(rs.getString("str_value_type"));
    action.stringValue = rs.getString("str_value");
    return action;
}
 
源代码7 项目: gemfirexd-oss   文件: UseCase4Client.java
private int holdingAgg(int acc) throws SQLException {
  int results = 0;
  if (holdingAggPS == null) {
    holdingAggPS = this.connection.prepareStatement(holdingAggStr);
  }
  holdingAggPS.setInt(1, acc);
  ResultSet rs = holdingAggPS.executeQuery();
  while (rs.next()) {
    rs.getString(1);
    rs.getFloat(2);
    ++results;
  }
  return results;
}
 
源代码8 项目: sqlhelper   文件: ResultSets.java
/**
 * Retrieve a JDBC column value from a ResultSet, using the specified value type.
 * <p>Uses the specifically typed ResultSet accessor methods, falling back to
 * {@link #getResultSetValue(java.sql.ResultSet, int)} for unknown types.
 * <p>Note that the returned value may not be assignable to the specified
 * required type, in case of an unknown type. Calling code needs to deal
 * with this case appropriately, e.g. throwing a corresponding exception.
 *
 * @param rs           is the ResultSet holding the data
 * @param index        is the column index
 * @param requiredType the required value type (may be {@code null})
 * @return the value object (possibly not of the specified required type,
 * with further conversion steps necessary)
 * @throws SQLException if thrown by the JDBC API
 * @see #getResultSetValue(ResultSet, int)
 */
@Nullable
public static Object getResultSetValue(ResultSet rs, int index, @Nullable Class<?> requiredType) throws SQLException {
    if (requiredType == null) {
        return getResultSetValue(rs, index);
    }

    Object value;

    // Explicitly extract typed value, as far as possible.
    if (String.class == requiredType) {
        return rs.getString(index);
    } else if (boolean.class == requiredType || Boolean.class == requiredType) {
        value = rs.getBoolean(index);
    } else if (byte.class == requiredType || Byte.class == requiredType) {
        value = rs.getByte(index);
    } else if (short.class == requiredType || Short.class == requiredType) {
        value = rs.getShort(index);
    } else if (int.class == requiredType || Integer.class == requiredType) {
        value = rs.getInt(index);
    } else if (long.class == requiredType || Long.class == requiredType) {
        value = rs.getLong(index);
    } else if (float.class == requiredType || Float.class == requiredType) {
        value = rs.getFloat(index);
    } else if (double.class == requiredType || Double.class == requiredType ||
            Number.class == requiredType) {
        value = rs.getDouble(index);
    } else if (BigDecimal.class == requiredType) {
        return rs.getBigDecimal(index);
    } else if (java.sql.Date.class == requiredType) {
        return rs.getDate(index);
    } else if (java.sql.Time.class == requiredType) {
        return rs.getTime(index);
    } else if (java.sql.Timestamp.class == requiredType || java.util.Date.class == requiredType) {
        return rs.getTimestamp(index);
    } else if (byte[].class == requiredType) {
        return rs.getBytes(index);
    } else if (Blob.class == requiredType) {
        return rs.getBlob(index);
    } else if (Clob.class == requiredType) {
        return rs.getClob(index);
    } else if (requiredType.isEnum()) {
        // Enums can either be represented through a String or an enum index value:
        // leave enum type conversion up to the caller (e.g. a ConversionService)
        // but make sure that we return nothing other than a String or an Integer.
        Object obj = rs.getObject(index);
        if (obj instanceof String) {
            return obj;
        } else if (obj instanceof Number) {
            // Defensively convert any Number to an Integer (as needed by our
            // ConversionService's IntegerToEnumConverterFactory) for use as index
            return Numbers.convertNumberToTargetClass((Number) obj, Integer.class);
        } else {
            // e.g. on Postgres: getObject returns a PGObject but we need a String
            return rs.getString(index);
        }
    } else {
        // Some unknown type desired -> rely on getObject.
        try {
            return Reflects.invokeAnyMethod(rs, "getObject", new Class[]{int.class, Class.class}, new Object[]{index, requiredType}, false, true);
            // return rs.getObject(index, requiredType);
        } catch (AbstractMethodError err) {
            logger.warn("JDBC driver does not implement JDBC 4.1 'getObject(int, Class)' method", err);
        } catch (Throwable ex) {
            logger.warn("JDBC driver has limited support for JDBC 4.1 'getObject(int, Class)' method", ex);
        }

        // Corresponding SQL types for JSR-310 / Joda-Time types, left up
        // to the caller to convert them (e.g. through a ConversionService).
        String typeName = requiredType.getSimpleName();
        if ("LocalDate".equals(typeName)) {
            return rs.getDate(index);
        } else if ("LocalTime".equals(typeName)) {
            return rs.getTime(index);
        } else if ("LocalDateTime".equals(typeName)) {
            return rs.getTimestamp(index);
        }

        // Fall back to getObject without type specification, again
        // left up to the caller to convert the value if necessary.
        return getResultSetValue(rs, index);
    }

    // Perform was-null check if necessary (for results that the JDBC driver returns as primitives).
    return (rs.wasNull() ? null : value);
}
 
源代码9 项目: dts   文件: ResultConvertUtils.java
private static Object getDataByType(int index, int columnType, ResultSet resultSet) throws SQLException {
    if (columnType == Types.BIT) {
        return resultSet.getByte(index);
    }
    if (columnType == Types.TINYINT) {
        return resultSet.getByte(index);
    }
    if (columnType == Types.SMALLINT) {
        return resultSet.getShort(index);
    }
    if (columnType == Types.INTEGER) {
        return resultSet.getInt(index);
    }
    if (columnType == Types.BIGINT) {
        return resultSet.getLong(index);
    }
    if (columnType == Types.FLOAT) {
        return resultSet.getFloat(index);
    }
    if (columnType == Types.DOUBLE) {
        return resultSet.getDouble(index);
    }
    if (columnType == Types.NUMERIC) {
        return resultSet.getInt(index);
    }
    if (columnType == Types.DECIMAL) {
        return resultSet.getBigDecimal(index);
    }
    if (columnType == Types.CHAR) {
        return resultSet.getString(index);
    }
    if (columnType == Types.VARCHAR) {
        return resultSet.getString(index);
    }
    if (columnType == Types.LONGNVARCHAR) {
        return resultSet.getString(index);
    }
    if (columnType == Types.DATE) {
        return resultSet.getDate(index);
    }
    if (columnType == Types.TIME) {
        return resultSet.getTime(index);
    }
    if (columnType == Types.NCHAR) {
        return resultSet.getNString(index);
    }
    if (columnType == Types.NVARCHAR) {
        return resultSet.getNString(index);
    }
    if (columnType == Types.OTHER) {
        return resultSet.getObject(index);
    }
    if (columnType == Types.BLOB) {
        return resultSet.getBlob(index);
    }
    if (columnType == Types.BOOLEAN) {
        return resultSet.getBoolean(index);
    }
    if (columnType == Types.ARRAY) {
        return resultSet.getArray(index);
    }
    if (columnType == Types.TIMESTAMP) {
        return resultSet.getTimestamp(index);
    }
    return resultSet.getObject(index);
}
 
源代码10 项目: amforeas   文件: AmforeasResultSetHandler.java
/**
 * Converts a ResultSet to a Map. Important to note that DATE, TIMESTAMP & TIME objects generate
 * a {@linkplain org.joda.time.DateTime} object using {@linkplain org.joda.time.format.ISODateTimeFormat}.
 * @param resultSet a {@linkplain java.sql.ResultSet}
 * @return a Map with the column names as keys and the values. null if something goes wrong.
 */
public static Map<String, Object> resultSetToMap (ResultSet resultSet) {
    Map<String, Object> map = new HashMap<>();
    try {
        int columnCount = resultSet.getMetaData().getColumnCount();

        l.trace("Mapping a result set with {} columns to a Map", columnCount);

        final ResultSetMetaData meta = resultSet.getMetaData();
        for (int i = 1; i < columnCount + 1; i++) {
            final String colName = meta.getColumnName(i).toLowerCase();
            final int colType = meta.getColumnType(i);

            if (Arrays.stream(ignore).anyMatch(sqlType -> colType == sqlType)) {
                l.trace("Ignoring column {} with type {}. Unsupported SQL Type.", colName, colType);
                continue;
            }

            Object v = null;

            if (resultSet.getObject(i) == null) {
                l.trace("Mapped {} column {} with value : {}", meta.getColumnTypeName(i), colName, v);
                map.put(colName, v);
                continue;
            }

            if (colType == Types.DATE) {
                v = new DateTime(resultSet.getDate(i)).toString(dateFTR);
                l.trace("Mapped DATE column {} with value : {}", colName, v);
            } else if (colType == Types.TIMESTAMP) {
                v = new DateTime(resultSet.getTimestamp(i)).toString(dateTimeFTR);
                l.trace("Mapped TIMESTAMP column {} with value : {}", colName, v);
            } else if (colType == Types.TIME) {
                v = new DateTime(resultSet.getTimestamp(i)).toString(timeFTR);
                l.trace("Mapped TIME column {} with value : {}", colName, v);
            } else if (colType == Types.DECIMAL) {
                v = resultSet.getBigDecimal(i);
                l.trace("Mapped DECIMAL column {} with value : {}", colName, v);
            } else if (colType == Types.FLOAT) {
                v = resultSet.getFloat(i);
                l.trace("Mapped FLOAT column {} with value : {}", colName, v);
            } else if (colType == Types.DOUBLE) {
                v = resultSet.getDouble(i);
                l.trace("Mapped DOUBLE column {} with value : {}", colName, v);
            } else if (colType == Types.TINYINT) {
                v = resultSet.getInt(i);
                l.trace("Mapped TINYINT column {} with value : {}", colName, v);
            } else if (colType == Types.SMALLINT) {
                v = resultSet.getInt(i);
                l.trace("Mapped SMALLINT column {} with value : {}", colName, v);
            } else if (colType == Types.INTEGER) {
                v = resultSet.getInt(i);
                l.trace("Mapped INTEGER column {} with value : {}", colName, v);
            } else if (colType == Types.BIGINT) {
                v = resultSet.getInt(i);
                l.trace("Mapped BIGINT column {} with value : {}", colName, v);
            } else {
                v = resultSet.getString(i);
                l.trace("Mapped {} column {} with value : {}", meta.getColumnTypeName(i), colName, v);
            }

            map.put(colName, v);
        }
    } catch (SQLException e) {
        l.error("Failed to map ResultSet");
        l.error(e.getMessage());
        return null;
    }

    return map;
}
 
源代码11 项目: data-generator   文件: Contract.java
@Override
protected Map<String, Object> getRow(ResultSet rs){
    Map<String, Object> data = new HashMap<>();
    try {
        int id = rs.getInt("id");
        float contract_price = rs.getFloat("contract_price");
        String state = rs.getString("state");
        String sign_day = rs.getString("sign_day");
        String sales_staff_name = rs.getString("sales_staff_name");
        String sales_staff_gender = rs.getString("sales_staff_gender");
        String customer_name = rs.getString("customer_name");
        String customer_gender = rs.getString("customer_gender");
        String customer_city = rs.getString("customer_city");
        String customer_city_full = rs.getString("customer_city_full");
        String customer_province = rs.getString("customer_province");
        String customer_province_full = rs.getString("customer_province_full");
        int dayofweek = rs.getInt("dayofweek");
        int weekofyear = rs.getInt("weekofyear");
        int month = rs.getInt("month");
        int dayofmonth = rs.getInt("dayofmonth");
        int quarter = rs.getInt("quarter");
        int year = rs.getInt("year");
        int dayofyear = rs.getInt("dayofyear");
        float longitude = rs.getFloat("longitude");
        float latitude = rs.getFloat("latitude");

        data.put("id", id);
        data.put("contract_price", contract_price);
        data.put("state", state);
        data.put("sign_day", sign_day.replace(" ", "T"));
        data.put("sales_staff_name", sales_staff_name);
        data.put("sales_staff_gender", sales_staff_gender);
        data.put("customer_name", customer_name);
        data.put("customer_gender", customer_gender);
        data.put("customer_city", customer_city);
        data.put("customer_city_full", customer_city_full);
        data.put("customer_province", customer_province);
        data.put("customer_province_full", customer_province_full);
        data.put("dayofweek", dayofweek);
        data.put("weekofyear", weekofyear);
        data.put("month", month);
        data.put("dayofmonth", dayofmonth);
        data.put("quarter", quarter);
        data.put("year", year);
        data.put("dayofyear", dayofyear);
        Map<String, Float> location = new HashMap<>();
        location.put("lon", longitude);
        location.put("lat", latitude);
        data.put("geo_location", location);
    }catch (Exception e){
        LOGGER.error("获取数据异常", e);
    }
    return data;
}
 
源代码12 项目: SimpleFlatMapper   文件: FloatResultSetGetter.java
@Override
public float getFloat(final ResultSet target) throws SQLException {
	return target.getFloat(column);
}
 
源代码13 项目: ralasafe   文件: ResultSetReader.java
public Object reader(ResultSet rs, int columnIndex) throws SQLException {
	return new Float(rs.getFloat(columnIndex));
}
 
源代码14 项目: OpenCue   文件: DispatcherDaoJdbc.java
public SortableShow mapRow(ResultSet rs, int rowNum) throws SQLException {
    return new SortableShow(
            rs.getString("pk_show"),
            rs.getFloat("float_tier"));
}
 
源代码15 项目: oxygen   文件: FloatColumnHandler.java
@Override
public Object fetch(ResultSet rs, int index) throws SQLException {
  return rs.getFloat(index);
}
 
源代码16 项目: Kylin   文件: DriverTest.java
@Ignore("not maintaining")
@Test
public void testWithCubeData() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    Driver driver = (Driver) Class.forName("org.apache.kylin.kylin.jdbc.Driver").newInstance();
    Properties info = new Properties();
    info.put("user", "");
    info.put("password", "");
    Connection conn = driver.connect("jdbc:kylin://localhost/default", info);

    ResultSet catalogs = conn.getMetaData().getCatalogs();
    while (catalogs.next()) {
        System.out.println(catalogs.getString("TABLE_CAT"));
    }

    ResultSet schemas = conn.getMetaData().getSchemas();
    while (schemas.next()) {
        System.out.println(schemas.getString(1));
        System.out.println(schemas.getString(2));
    }

    ResultSet tables = conn.getMetaData().getTables(null, null, null, null);
    while (tables.next()) {
        String tableName = tables.getString(3);
        assertEquals(tables.getString("TABLE_NAME"), tableName);
        ResultSet columns = conn.getMetaData().getColumns(null, null, tableName, null);

        while (columns.next()) {
            System.out.println(columns.getString("COLUMN_NAME"));
            String column = "";
            for (int i = 0; i < 23; i++) {
                column += columns.getString(i + 1) + ", ";
            }

            System.out.println("Column in table " + tableName + ": " + column);
        }
    }

    for (int j = 0; j < 3; j++) {
        Statement state = conn.createStatement();
        ResultSet resultSet = state.executeQuery("select * from test_kylin_fact");

        ResultSetMetaData metadata = resultSet.getMetaData();
        System.out.println("Metadata:");

        for (int i = 0; i < metadata.getColumnCount(); i++) {
            String metaStr = metadata.getCatalogName(i + 1) + " " + metadata.getColumnClassName(i + 1) + " " + metadata.getColumnDisplaySize(i + 1) + " " + metadata.getColumnLabel(i + 1) + " " + metadata.getColumnName(i + 1) + " " + metadata.getColumnType(i + 1) + " " + metadata.getColumnTypeName(i + 1) + " " + metadata.getPrecision(i + 1) + " " + metadata.getScale(i + 1) + " " + metadata.getSchemaName(i + 1) + " " + metadata.getTableName(i + 1);
            System.out.println(metaStr);
        }

        System.out.println("Data:");
        while (resultSet.next()) {
            String dataStr = resultSet.getFloat(1) + " " + resultSet.getInt(2) + " " + resultSet.getInt(3) + " " + resultSet.getLong(4) + " " + resultSet.getDate(5) + " " + resultSet.getString(6);
            System.out.println(dataStr);
        }
    }
}
 
源代码17 项目: sqlg   文件: TestVertexCreation.java
@Test
public void testCreateVertexWithProperties() throws SQLException {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsFloatValues());
    sqlgGraph.addVertex(T.label, "Person",
            "boolean1", true,
            "short1", (short) 1,
            "integer1", 1,
            "long1", 1L,
            "float1", 1F,
            "double1", 1D,
            "name", "marko"
    );
    sqlgGraph.addVertex(T.label, "Person",
            "boolean1", true,
            "short1", (short) 1,
            "integer1", 1,
            "long1", 1L,
            "float1", 1F,
            "double1", 1D,
            "name", "marko"
    );
    sqlgGraph.tx().commit();

    try (Connection conn = this.sqlgGraph.getConnection()) {
        try (Statement stmt = conn.createStatement()) {
            StringBuilder sql = new StringBuilder("SELECT * FROM ");
            sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.sqlgGraph.getSqlDialect().getPublicSchema()));
            sql.append(".");
            sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(Topology.VERTEX_PREFIX + "Person"));
            if (this.sqlgGraph.getSqlDialect().needsSemicolon()) {
                sql.append(";");
            }
            ResultSet rs = stmt.executeQuery(sql.toString());
            int countRows = 0;
            boolean boolean1 = false;
            short short1 = (short) -1;
            int integer1 = -1;
            long long1 = -1L;
            float float1 = -1F;
            double double1 = -1D;
            String name = "";
            while (rs.next()) {
                boolean1 = rs.getBoolean("boolean1");
                short1 = rs.getShort("short1");
                integer1 = rs.getInt("integer1");
                long1 = rs.getLong("long1");
                float1 = rs.getFloat("float1");
                double1 = rs.getDouble("double1");
                name = rs.getString("name");
                countRows++;
            }
            assertEquals(2, countRows);
            assertEquals(boolean1, true);
            assertEquals(short1, (short) 1);
            assertEquals(integer1, 1);
            assertEquals(long1, 1L);
            assertEquals(float1, 1F, 0);
            assertEquals(double1, 1D, 0);
            assertEquals("marko", name);
            rs.close();
        }
    }
}
 
/**
 * Auxiliary method for testing column access.
 *
 * @param resultSet Result set
 * @param index Index of the column to be accessed
 * @param shouldThrow Whether the column access should throw an exception
 * @return Whether the method invocation succeeded
 * @throws SQLException in case of database error
 */
private boolean getColumn(final ResultSet resultSet, final int index,
    final boolean shouldThrow) throws SQLException {
  try {
    switch (index) {
    case 1: // BOOLEAN
      resultSet.getBoolean(index);
      break;
    case 2: // TINYINT
      resultSet.getByte(index);
      break;
    case 3: // SMALLINT
      resultSet.getShort(index);
      break;
    case 4: // INTEGER
      resultSet.getInt(index);
      break;
    case 5: // BIGINT
      resultSet.getLong(index);
      break;
    case 6: // REAL
      resultSet.getFloat(index);
      break;
    case 7: // FLOAT
      resultSet.getDouble(index);
      break;
    case 8: // VARCHAR
      resultSet.getString(index);
      break;
    case 9: // DATE
      resultSet.getDate(index);
      break;
    case 10: // TIME
      resultSet.getTime(index);
      break;
    case 11: // TIMESTAMP
      resultSet.getTimestamp(index);
      break;
    default:
      resultSet.getObject(index);
    }
  } catch (SQLException e) {
    if (!shouldThrow) {
      throw e;
    }
    return true;
  }

  return !shouldThrow;
}
 
源代码19 项目: data-generator   文件: ContractDetail.java
@Override
protected Map<String, Object> getRow(ResultSet rs){
    Map<String, Object> data = new HashMap<>();
    try {
        int id = rs.getInt("id");
        float contract_price = rs.getFloat("contract_price");
        String state = rs.getString("state");
        String sign_day = rs.getString("sign_day").replace(" ", "T");
        String sales_staff_name = rs.getString("sales_staff_name");
        String sales_staff_gender = rs.getString("sales_staff_gender");
        String customer_name = rs.getString("customer_name");
        String customer_gender = rs.getString("customer_gender");
        String customer_city = rs.getString("customer_city");
        String customer_city_full = rs.getString("customer_city_full");
        String customer_province = rs.getString("customer_province");
        String customer_province_full = rs.getString("customer_province_full");
        int dayofweek = rs.getInt("dayofweek");
        int weekofyear = rs.getInt("weekofyear");
        int month = rs.getInt("month");
        int dayofmonth = rs.getInt("dayofmonth");
        int quarter = rs.getInt("quarter");
        int year = rs.getInt("year");
        int dayofyear = rs.getInt("dayofyear");
        float contract_detail_price = rs.getFloat("contract_detail_price");
        float item_quantity = rs.getFloat("item_quantity");
        String item_name = rs.getString("item_name");
        float item_price = rs.getFloat("item_price");
        float longitude = rs.getFloat("longitude");
        float latitude = rs.getFloat("latitude");
        float discount = rs.getFloat("discount");
        String color = rs.getString("color");
        String brand_name = rs.getString("brand_name");
        String category_name = rs.getString("category_name");

        data.put("id", id);
        data.put("contract_price", contract_price);
        data.put("state", state);
        data.put("sign_day", sign_day);
        data.put("sales_staff_name", sales_staff_name);
        data.put("sales_staff_gender", sales_staff_gender);
        data.put("customer_name", customer_name);
        data.put("customer_gender", customer_gender);
        data.put("customer_city", customer_city);
        data.put("customer_city_full", customer_city_full);
        data.put("customer_province", customer_province);
        data.put("customer_province_full", customer_province_full);
        data.put("dayofweek", dayofweek);
        data.put("weekofyear", weekofyear);
        data.put("month", month);
        data.put("dayofmonth", dayofmonth);
        data.put("quarter", quarter);
        data.put("year", year);
        data.put("dayofyear", dayofyear);
        data.put("contract_detail_price", contract_detail_price);
        data.put("item_quantity", item_quantity);
        data.put("item_name", item_name);
        data.put("item_price", item_price);
        data.put("discount", discount);
        data.put("color", color);
        data.put("brand_name", brand_name);
        data.put("category_name", category_name);
        Map<String, Float> location = new HashMap<>();
        location.put("lon", longitude);
        location.put("lat", latitude);
        data.put("geo_location", location);
    }catch (Exception e){
        LOGGER.error("获取数据异常", e);
    }
    return data;
}
 
源代码20 项目: ats-framework   文件: PGDbReadAccess.java
/**
 * Currently used by {@link AtsDbReader#getStatisticsDescriptionForDateRange(int, int, int, long, long)}
 * */
public List<Statistic> getSystemStatistics( String testcaseIds,
                                            String machineIds,
                                            String statsTypeIds,
                                            String whereClause ) throws DatabaseAccessException {

    List<Statistic> allStatistics = new ArrayList<Statistic>();

    String sqlLog = new SqlRequestFormatter().add("testcase ids", testcaseIds)
                                             .add("machine ids", machineIds)
                                             .add("stats type ids", statsTypeIds)
                                             .add("where", whereClause)
                                             .format();

    Connection connection = getConnection();
    PreparedStatement prepareStatement = null;
    ResultSet rs = null;

    try {
        int numberRecords = 0;
        StringBuilder query = new StringBuilder();
        query.append("SELECT")
             .append(" st.name as statsName, st.units as statsUnit, st.params, st.parentName as statsParent, st.internalName,")
             .append(" ss.systemStatsId, ss.testcaseId, ss.machineId as machineId, ss.statsTypeId as statsTypeId, ss.timestamp as timestamp, ss.value as value,")
             .append(" t.testcaseId as testcaseId")
             .append(" FROM \"tSystemStats\" ss")
             .append(" INNER JOIN \"tStatsTypes\" st ON ss.statsTypeId = st.statsTypeId")
             .append(" INNER JOIN \"tTestcases\"  t ON ss.testcaseId = t.testcaseId")
             .append(" WHERE")
             .append(" t.testcaseId IN (" + testcaseIds + ")")
             .append(" AND ss.statsTypeId IN (" + statsTypeIds + ")")
             .append(" AND ss.machineId IN (" + machineIds + ")")
             .append(" AND " + whereClause);

        prepareStatement = connection.prepareStatement(query.toString());
        rs = prepareStatement.executeQuery();
        while (rs.next()) {
            Statistic statistic = new Statistic();
            statistic.statisticTypeId = rs.getInt("statsTypeId");
            statistic.name = rs.getString("statsName");
            statistic.parentName = rs.getString("statsParent");
            statistic.unit = rs.getString("statsUnit");
            statistic.value = rs.getFloat("value");
            statistic.machineId = rs.getInt("machineId");
            statistic.testcaseId = rs.getInt("testcaseId");

            long startTimestamp = rs.getTimestamp("timestamp").getTime();
            statistic.setStartTimestamp(startTimestamp);
            statistic.setEndTimestamp(startTimestamp);

            numberRecords++;
            // add the combined statistics to the others
            allStatistics.add(statistic);
        }

        logQuerySuccess(sqlLog, "system statistics", numberRecords);
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, prepareStatement);
    }

    return allStatistics;
}