java.sql.ResultSet.getDouble()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(260)

本文整理了Java中java.sql.ResultSet.getDouble方法的一些代码示例,展示了ResultSet.getDouble的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ResultSet.getDouble方法的具体详情如下:
包路径:java.sql.ResultSet
类名称:ResultSet
方法名:getDouble

ResultSet.getDouble介绍

[英]Gets the value of a column specified by column index as a doublevalue.
[中]获取列索引指定为doublevalue的列的值。

代码示例

代码示例来源:origin: nutzam/nutz

public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
  if (null != rs && rs.next())
    return rs.getDouble(1);
  return null;
}

代码示例来源:origin: SonarSource/sonarqube

@CheckForNull
public static Double getDouble(ResultSet rs, int columnIndex) throws SQLException {
 double d = rs.getDouble(columnIndex);
 return rs.wasNull() ? null : d;
}

代码示例来源:origin: Netflix/conductor

protected <V> V getScalarFromResultSet(ResultSet rs, Class<V> returnType) throws SQLException {
  Object value = null;
  if (Integer.class == returnType) {
    value = rs.getInt(1);
  } else if (Long.class == returnType) {
    value = rs.getLong(1);
  } else if (String.class == returnType) {
    value = rs.getString(1);
  } else if (Boolean.class == returnType) {
    value = rs.getBoolean(1);
  } else if (Double.class == returnType) {
    value = rs.getDouble(1);
  } else if (Date.class == returnType) {
    value = rs.getDate(1);
  } else if (Timestamp.class == returnType) {
    value = rs.getTimestamp(1);
  } else {
    value = rs.getObject(1);
  }
  if (null == value) {
    throw new NullPointerException("Cannot get value from ResultSet of type " + returnType.getName());
  }
  return returnType.cast(value);
}

代码示例来源:origin: apache/phoenix

private void testUnsignedNumberSpec(Connection conn, double data) throws Exception {
  updateUnsignedTable(conn, data);
  ResultSet rs = conn.createStatement().executeQuery("SELECT SQRT(doub),SQRT(fl),SQRT(inte),SQRT(lon),SQRT(smalli),SQRT(tinyi) FROM " + testUnsignedTable );
  assertTrue(rs.next());
  Double d = Double.valueOf(data);
  assertTrue(Math.abs(rs.getDouble(1) - Math.sqrt(d.doubleValue())) < ZERO);
  assertTrue(Math.abs(rs.getDouble(2) - Math.sqrt(d.floatValue())) < ZERO);
  assertTrue(Math.abs(rs.getDouble(3) - Math.sqrt(d.intValue())) < ZERO);
  assertTrue(Math.abs(rs.getDouble(4) - Math.sqrt(d.longValue())) < ZERO);
  assertTrue(Math.abs(rs.getDouble(5) - Math.sqrt(d.shortValue())) < ZERO);
  assertTrue(Math.abs(rs.getDouble(6) - Math.sqrt(d.byteValue())) < ZERO);
  assertTrue(!rs.next());
  PreparedStatement stmt = conn.prepareStatement("SELECT k FROM " + testUnsignedTable + " WHERE SQRT(doub)>0 AND SQRT(fl)>0 AND SQRT(inte)>0 AND SQRT(lon)>0 AND SQRT(smalli)>0 AND SQRT(tinyi)>0");
  rs = stmt.executeQuery();
  if (data > 0) {
    assertTrue(rs.next());
    assertEquals(KEY, rs.getString(1));
  }
  assertTrue(!rs.next());
}

代码示例来源:origin: apache/ignite

@Override public void run(Connection conn) throws Exception {
    try (PreparedStatement stmt = conn.prepareStatement("SELECT 'zzz'")) {
      ResultSet rs = stmt.executeQuery();
      rs.next();
      rs.getDouble(1);
    }
  }
}, "0700B", "Cannot convert to double");

代码示例来源:origin: apache/cloudstack

@Override
public Pair<List<Long>, Map<Long, Double>> listClusterIdsInZoneByVmCount(long zoneId, long accountId) {
  TransactionLegacy txn = TransactionLegacy.currentTxn();
  PreparedStatement pstmt = null;
  List<Long> result = new ArrayList<Long>();
  Map<Long, Double> clusterVmCountMap = new HashMap<Long, Double>();
  StringBuilder sql = new StringBuilder(ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART1);
  sql.append("host.data_center_id = ?");
  sql.append(ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART2);
  try {
    pstmt = txn.prepareAutoCloseStatement(sql.toString());
    pstmt.setLong(1, accountId);
    pstmt.setLong(2, zoneId);
    ResultSet rs = pstmt.executeQuery();
    while (rs.next()) {
      Long clusterId = rs.getLong(1);
      result.add(clusterId);
      clusterVmCountMap.put(clusterId, rs.getDouble(2));
    }
    return new Pair<List<Long>, Map<Long, Double>>(result, clusterVmCountMap);
  } catch (SQLException e) {
    throw new CloudRuntimeException("DB Exception on: " + sql, e);
  } catch (Throwable e) {
    throw new CloudRuntimeException("Caught: " + sql, e);
  }
}

代码示例来源:origin: apache/hive

System.out.print("\n");
if (rs.next()) {
 int i = 0, cc = 11;
 String cntRows = rs.getString(1);
   "Min", "Max", "StdDev", "p05", "p25", "p50", "p75", "p95"));          
 for(Column c : row.getColumns()) {
  String avg = String.format("%.2f", rs.getDouble(4 + i*cc));
  if (rs.wasNull())
   avg = "null";
  String stddev = String.format("%.2f", rs.getDouble(7 + i*cc));
  if (rs.wasNull())
   stddev = "null";
  String p05 = String.format("%.2f", rs.getDouble(8 + i*cc));
  if (rs.wasNull())
   p05 = "null";
  String p25 = String.format("%.2f", rs.getDouble(9 + i*cc));
  String p50 = String.format("%.2f", rs.getDouble(10 + i*cc));
  String p75 = String.format("%.2f", rs.getDouble(11 + i*cc));
  String p95 = String.format("%.2f", rs.getDouble(12 + i*cc));

代码示例来源:origin: apache/nifi

final int nrOfColumns = meta.getColumnCount();
long nrOfRows = 0;
while (rs.next()) {
  if (callback != null) {
    callback.processRow(rs);
        value = rs.getFloat(i);
      } else if (javaSqlType == DOUBLE) {
        value = rs.getDouble(i);
      } else if (javaSqlType == INTEGER || javaSqlType == TINYINT || javaSqlType == SMALLINT) {
        value = rs.getInt(i);

代码示例来源:origin: spring-projects/spring-batch

@Override
  public void processRow(ResultSet rs) throws SQLException {
    ParameterType type = ParameterType.valueOf(rs.getString(3));
    JobParameter value = null;
    if (type == ParameterType.STRING) {
      value = new JobParameter(rs.getString(4), rs.getString(8).equalsIgnoreCase("Y"));
    } else if (type == ParameterType.LONG) {
      value = new JobParameter(rs.getLong(6), rs.getString(8).equalsIgnoreCase("Y"));
    } else if (type == ParameterType.DOUBLE) {
      value = new JobParameter(rs.getDouble(7), rs.getString(8).equalsIgnoreCase("Y"));
    } else if (type == ParameterType.DATE) {
      value = new JobParameter(rs.getTimestamp(5), rs.getString(8).equalsIgnoreCase("Y"));
    }
    // No need to assert that value is not null because it's an enum
    map.put(rs.getString(2), value);
  }
};

代码示例来源:origin: apache/tika

case Types.DECIMAL:
case Types.NUMERIC:
  double dbl = rs.getDouble(colIndex);
  if (rs.wasNull()) {
    cell.setCellValue(NULL_VALUE);
  } else {
case Types.VARCHAR:
case Types.LONGNVARCHAR:
  String val = rs.getString(colIndex);
  if (rs.wasNull()) {
    cell.setCellValue(NULL_VALUE);
  } else {
  if (rs.wasNull()) {
    cell.setCellValue(NULL_VALUE);
  } else {
    cell.setCellValue(rs.getString(colIndex));

代码示例来源:origin: spring-projects/spring-batch

@Override
  public void processRow(ResultSet rs) throws SQLException {
    Customer customer = customers.get(activeRow++);
    assertEquals(customer.getName(),rs.getString(1));
    assertEquals(customer.getCredit(), rs.getDouble(2), .01);
  }
});

代码示例来源:origin: spring-projects/spring-framework

return rs.getString(index);
  value = rs.getInt(index);
  value = rs.getLong(index);
  value = rs.getDouble(index);
    return rs.getString(index);
return (rs.wasNull() ? null : value);

代码示例来源:origin: apache/phoenix

private void testSignedNumberSpec(Connection conn, double data) throws Exception {
  updateSignedTable(conn, data);
  ResultSet rs = conn.createStatement().executeQuery("SELECT SQRT(doub),SQRT(fl),SQRT(inte),SQRT(lon),SQRT(smalli),SQRT(tinyi) FROM " + testSignedTable );
  assertTrue(rs.next());
  Double d = Double.valueOf(data);
  assertTrue(Math.abs(rs.getDouble(1) - Math.sqrt(d.doubleValue())) < ZERO);
  assertTrue(Math.abs(rs.getDouble(2) - Math.sqrt(d.floatValue())) < ZERO);
  assertTrue(Math.abs(rs.getDouble(3) - Math.sqrt(d.intValue())) < ZERO);
  assertTrue(Math.abs(rs.getDouble(4) - Math.sqrt(d.longValue())) < ZERO);
  assertTrue(Math.abs(rs.getDouble(5) - Math.sqrt(d.shortValue())) < ZERO);
  assertTrue(Math.abs(rs.getDouble(6) - Math.sqrt(d.byteValue())) < ZERO);
  assertTrue(!rs.next());
  PreparedStatement stmt = conn.prepareStatement("SELECT k FROM " + testSignedTable + " WHERE SQRT(doub)>0 AND SQRT(fl)>0 AND SQRT(inte)>0 AND SQRT(lon)>0 AND SQRT(smalli)>0 AND SQRT(tinyi)>0");
  rs = stmt.executeQuery();
  if (data > 0) {
    assertTrue(rs.next());
    assertEquals(KEY, rs.getString(1));
  }
  assertTrue(!rs.next());
}

代码示例来源:origin: mapsforge/mapsforge

/**
 * Find a <code>Node</code> by its ID.
 */
LatLong findNodeByID(long id) {
  try {
    this.pStmtNodesR.setLong(1, id);
    ResultSet rs = this.pStmtNodesR.executeQuery();
    if (rs.next()) {
      double lat = rs.getDouble(1);
      double lon = rs.getDouble(2);
      return new LatLong(lat, lon);
    }
    rs.close();
  } catch (SQLException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: apache/cloudstack

@Override
public Pair<List<Long>, Map<Long, Double>> listClusterIdsInPodByVmCount(long podId, long accountId) {
  TransactionLegacy txn = TransactionLegacy.currentTxn();
  PreparedStatement pstmt = null;
  List<Long> result = new ArrayList<Long>();
  Map<Long, Double> clusterVmCountMap = new HashMap<Long, Double>();
  StringBuilder sql = new StringBuilder(ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART1);
  sql.append("host.pod_id = ?");
  sql.append(ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART2);
  try {
    pstmt = txn.prepareAutoCloseStatement(sql.toString());
    pstmt.setLong(1, accountId);
    pstmt.setLong(2, podId);
    ResultSet rs = pstmt.executeQuery();
    while (rs.next()) {
      Long clusterId = rs.getLong(1);
      result.add(clusterId);
      clusterVmCountMap.put(clusterId, rs.getDouble(2));
    }
    return new Pair<List<Long>, Map<Long, Double>>(result, clusterVmCountMap);
  } catch (SQLException e) {
    throw new CloudRuntimeException("DB Exception on: " + sql, e);
  } catch (Throwable e) {
    throw new CloudRuntimeException("Caught: " + sql, e);
  }
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testDouble() throws Exception {
  ResultSet rs = stmt.executeQuery(SQL);
  int cnt = 0;
  while (rs.next()) {
    if (cnt == 0) {
      assert rs.getDouble("doubleVal") == 1.0;
      assert rs.getDouble(8) == 1.0;
    }
    cnt++;
  }
  assert cnt == 1;
}

代码示例来源:origin: apache/nifi

final int nrOfColumns = meta.getColumnCount();
long nrOfRows = 0;
while (rs.next()) {
  if (callback != null) {
    callback.processRow(rs);
        value = rs.getFloat(i);
      } else if (javaSqlType == DOUBLE) {
        value = rs.getDouble(i);
      } else if (javaSqlType == INTEGER || javaSqlType == TINYINT || javaSqlType == SMALLINT) {
        value = rs.getInt(i);

代码示例来源:origin: apache/hive

/**
 * Set the new value from the result set
 */
public Var setValue(ResultSet rs, ResultSetMetaData rsm, int idx) throws SQLException {
 int type = rsm.getColumnType(idx);
 if (type == java.sql.Types.CHAR || type == java.sql.Types.VARCHAR) {
  cast(new Var(rs.getString(idx)));
 }
 else if (type == java.sql.Types.INTEGER || type == java.sql.Types.BIGINT ||
   type == java.sql.Types.SMALLINT || type == java.sql.Types.TINYINT) {
  cast(new Var(new Long(rs.getLong(idx))));
 }
 else if (type == java.sql.Types.DECIMAL || type == java.sql.Types.NUMERIC) {
  cast(new Var(rs.getBigDecimal(idx)));
 }
 else if (type == java.sql.Types.FLOAT || type == java.sql.Types.DOUBLE) {
  cast(new Var(new Double(rs.getDouble(idx))));
 }
 return this;
}

代码示例来源:origin: apache/tika

if (! results.wasNull()) {
  addAllCharacters(Float.toString(f), handler);
double d = results.getDouble(i);
if (! results.wasNull()) {
  addAllCharacters(Double.toString(d), handler);
String s = results.getString(i);
if (!results.wasNull()) {
  addAllCharacters(s, handler);

代码示例来源:origin: SonarSource/sonarqube

@CheckForNull
public Double getNullableDouble(int columnIndex) throws SQLException {
 double d = rs.getDouble(columnIndex);
 return rs.wasNull() ? null : d;
}

相关文章

微信公众号

最新文章

更多

ResultSet类方法