Java Code Examples for java.sql.ResultSet.getBigDecimal()

The following are Jave code examples for showing how to use getBigDecimal() of the java.sql.ResultSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DrugStoreManagement   File: SalesmanDao.java   View Source Code Vote up 7 votes
public BigDecimal getOutNum()
{
	Connection connection;
	try {
		connection = JDBCTools.getConnection();
		String sql = "select sum(Salary) from Salesman where OnDuty = 1";
		PreparedStatement pstmt = connection.prepareStatement(sql);
		ResultSet rs = pstmt.executeQuery();
		rs.next();
		BigDecimal a = rs.getBigDecimal(1);
		JDBCTools.releaseConnection(connection, pstmt, rs);
		return a;
	} catch (SQLException e) {
		return new BigDecimal(0);
	}
}
 
Example 2
Project: lams   File: IdentifierGeneratorHelper.java   View Source Code Vote up 6 votes
public IntegralDataTypeHolder initialize(ResultSet resultSet, long defaultValue) throws SQLException {
	final BigDecimal rsValue = resultSet.getBigDecimal( 1 );
	if ( resultSet.wasNull() ) {
		return initialize( defaultValue );
	}
	this.value = rsValue.setScale( 0, BigDecimal.ROUND_UNNECESSARY );
	return this;
}
 
Example 3
Project: HueSense   File: TempSensor.java   View Source Code Vote up 6 votes
@Override
public Set<SensorValue<BigDecimal>> getValuesInRange(Date start, Date end) {
    NavigableSet<SensorValue<BigDecimal>> ret = new TreeSet<>();

    try (Connection conn = dbMan.getConnection()) {
        try (PreparedStatement stmt = conn.prepareStatement(SELECT_RANGE)) {
            stmt.setLong(1, dbId);
            stmt.setTimestamp(2, new Timestamp(start.getTime()));
            long endTime = end == null ? System.currentTimeMillis() : end.getTime();
            stmt.setTimestamp(3, new Timestamp(endTime));
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                SensorValue<BigDecimal> val = new SensorValue<>(rs.getTimestamp("CREATED"), rs.getBigDecimal("TEMPERATURE"));
                ret.add(val);
            }
        }
    } catch (SQLException ex) {
        LOG.error("Error querying temp values", ex);
    }
    return ret;
}
 
Example 4
Project: DrugStoreManagement   File: ManagerDao.java   View Source Code Vote up 6 votes
public BigDecimal getOutNum()
{
	Connection connection;
	try {
		connection = JDBCTools.getConnection();
		String sql = "select sum(Salary) from Manager where OnDuty = 1";
		PreparedStatement pstmt = connection.prepareStatement(sql);
		ResultSet rs = pstmt.executeQuery();
		rs.next();
		BigDecimal a = rs.getBigDecimal(1);
		JDBCTools.releaseConnection(connection, pstmt, rs);
		return a;
	} catch (SQLException e) {
		return new BigDecimal(-1);
	}
}
 
Example 5
Project: morf   File: ResultSetComparer.java   View Source Code Vote up 6 votes
@SuppressWarnings("rawtypes")
private Comparable columnToValue(ResultSet resultSet, int columnIndex, int columnType) throws SQLException {
  if (columnTypeIsString(columnType)) {
    return resultSet.getString(columnIndex);
  } else if (columnTypeIsNumeric(columnType)) {
    BigDecimal bigDecimal = resultSet.getBigDecimal(columnIndex);
    return bigDecimal == null ? null : bigDecimal.stripTrailingZeros();
  } else if (columnTypeIsBoolean(columnType)) {
    return resultSet.getBoolean(columnIndex);
  } else if (columnTypeIsDate(columnType)) {
    return resultSet.getDate(columnIndex);
  } else {
    throw new IllegalArgumentException("Column type " + columnType + " not supported for comparison");
  }
}
 
Example 6
Project: ChronoBike   File: RecordColTypeManagerDecimal.java   View Source Code Vote up 6 votes
public boolean transfer(int nColumnNumber1Based, ResultSet resultSetSource, PreparedStatement insertStatementInsert)
{
	try
	{			
		BigDecimal value = resultSetSource.getBigDecimal(m_nColSourceIndex);
		if (!resultSetSource.wasNull())
			insertStatementInsert.setBigDecimal(m_nColSourceIndex, value);
		else
			insertStatementInsert.setNull(m_nColSourceIndex, Types.DECIMAL);			
		return true;
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}
	return false;		
}
 
Example 7
Project: ChronoBike   File: RecordColTypeManagerDecimal.java   View Source Code Vote up 6 votes
boolean fillColValue(ResultSet rs, VarBase varInto)
{
	try
	{		
		BigDecimal bdValue = rs.getBigDecimal(m_nColSourceIndex);
		if(bdValue != null)
		{
			varInto.m_varDef.write(varInto.m_bufferPos, bdValue);
			return false;
		}
	}
	catch (SQLException e)
	{
		LogSQLException.log(e);
		// Maybe should I set m_bNull = true; ?
	}
	varInto.m_varDef.write(varInto.m_bufferPos, 0);
	return true;
}
 
Example 8
Project: calcite-avatica   File: RemoteDriverTest.java   View Source Code Vote up 6 votes
@Test public void testBigDecimalPrecision() throws Exception {
  final String tableName = "decimalPrecision";
  // DECIMAL(25,5), 20 before, 5 after
  BigDecimal decimal = new BigDecimal("12345123451234512345.09876");
  try (Connection conn = getLocalConnection();
      Statement stmt = conn.createStatement()) {
    assertFalse(stmt.execute("DROP TABLE IF EXISTS " + tableName));
    assertFalse(stmt.execute("CREATE TABLE " + tableName + " (col1 DECIMAL(25,5))"));

    // Insert a single decimal
    try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + tableName
        + " values (?)")) {
      pstmt.setBigDecimal(1, decimal);
      assertEquals(1, pstmt.executeUpdate());
    }

    ResultSet results = stmt.executeQuery("SELECT * FROM " + tableName);
    assertNotNull(results);
    assertTrue(results.next());
    BigDecimal actualDecimal = results.getBigDecimal(1);
    assertEquals(decimal, actualDecimal);
  }
}
 
Example 9
Project: DrugStoreManagement   File: StoreDao.java   View Source Code Vote up 6 votes
public BigDecimal getOutNum()
{
	Connection connection;
	try {
		connection = JDBCTools.getConnection();
		String sql = "select sum(MonthlyCost) from Store";
		PreparedStatement pstmt = connection.prepareStatement(sql);
		ResultSet rs = pstmt.executeQuery();
		rs.next();
		BigDecimal a = rs.getBigDecimal(1);
		JDBCTools.releaseConnection(connection, pstmt, rs);
		return a;
	} catch (SQLException e) {
		return new BigDecimal(0);
	}
}
 
Example 10
Project: DrugStoreManagement   File: WarehouseManagerDao.java   View Source Code Vote up 6 votes
public BigDecimal getOutNum()
{
	Connection connection;
	try {
		connection = JDBCTools.getConnection();
		String sql = "select sum(Salary) from WarehouseManager where OnDuty = 1";
		PreparedStatement pstmt = connection.prepareStatement(sql);
		ResultSet rs = pstmt.executeQuery();
		rs.next();
		BigDecimal a = rs.getBigDecimal(1);
		JDBCTools.releaseConnection(connection, pstmt, rs);
		return a;
	} catch (SQLException e) {
		return new BigDecimal(0);
	}
}
 
Example 11
Project: ChronoBike   File: DbColDefinitionDecimal.java   View Source Code Vote up 5 votes
public byte[] getByteValue(ResultSet resultSet, int nCol1Based, boolean bEbcdicOutput)
{
	try
	{
		ResultSetMetaData rsMetaData = resultSet.getMetaData();

		int nNbDigits = rsMetaData.getPrecision(nCol1Based);
		int nNbDecimals = rsMetaData.getScale(nCol1Based);
		Asserter.assertIfFalse(nNbDigits == m_nNbDigits);
		Asserter.assertIfFalse(nNbDecimals == m_nNbDecimals);

		if((nNbDigits % 2) == 0)
			nNbDigits++;
		int nNbCharsInComp3 = (nNbDigits / 2) + 1;
		
		BigDecimal bd = resultSet.getBigDecimal(nCol1Based);
		DecBase decValue = DecBase.toDec(bd);
		
		byte [] aBytes = new byte[nNbCharsInComp3];
		
		boolean bPositive = !decValue.isNegative();
		String cs = Comp3Support.encodeDecComp3(decValue, m_nNbDigits-m_nNbDecimals, m_nNbDecimals);
		Comp3Support.internalWriteEncodeComp3(aBytes, cs, bPositive, true);
					
		//m_nPhysicalPosInRecordSet += nNbCharsInComp3;
		return aBytes;					
	}
	catch (SQLException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
Example 12
Project: tangyuan2   File: BigIntegerTypeHandler.java   View Source Code Vote up 5 votes
@Override
public BigInteger getNullableResult(ResultSet rs, String columnName) throws SQLException {
	BigDecimal bigDecimal = rs.getBigDecimal(columnName);
	return bigDecimal == null ? null : bigDecimal.toBigInteger();
}
 
Example 13
Project: sample.daytrader3   File: TradeDirect.java   View Source Code Vote up 5 votes
private OrderDataBean getOrderDataFromResultSet(ResultSet rs)
		throws Exception {
	OrderDataBean orderData = null;

	orderData = new OrderDataBean(new Integer(rs.getInt("orderID")), rs
			.getString("orderType"), rs.getString("orderStatus"), rs
			.getTimestamp("openDate"), rs.getTimestamp("completionDate"),
			rs.getDouble("quantity"), rs.getBigDecimal("price"), rs
					.getBigDecimal("orderFee"), rs
					.getString("quote_symbol"));
	return orderData;
}
 
Example 14
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 5 votes
public Object getResult(ResultSet rs, String columnName) throws SQLException {

            Object bigdec = rs.getBigDecimal(columnName);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return bigdec;
            }
        }
 
Example 15
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 5 votes
public Object getResult(ResultSet rs, int columnIndex) throws SQLException {

            Object bigdec = rs.getBigDecimal(columnIndex);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return bigdec;
            }
        }
 
Example 16
Project: sample.daytrader3   File: TradeDirect.java   View Source Code Vote up 5 votes
private QuoteDataBean getQuoteDataFromResultSet(ResultSet rs)
		throws Exception {
	QuoteDataBean quoteData = null;

	quoteData = new QuoteDataBean(rs.getString("symbol"), rs
			.getString("companyName"), rs.getDouble("volume"), rs
			.getBigDecimal("price"), rs.getBigDecimal("open1"), rs
			.getBigDecimal("low"), rs.getBigDecimal("high"), rs
			.getDouble("change1"));
	return quoteData;
}
 
Example 17
Project: synthea_java   File: ReportExporter.java   View Source Code Vote up 4 votes
private static void processCosts(Connection connection, JsonWriter writer)
    throws IOException, SQLException {
  writer.name("costs").beginObject();

  PreparedStatement stmt = connection.prepareStatement(
      "select year, type, sum(cost) from "
      + "(SELECT c.cost, YEAR(DATEADD('SECOND', e.start/ 1000 , DATE '1970-01-01')) as year, "
      + "e.type FROM ENCOUNTER e, CLAIM c where e.id = c.encounter_id) group by year, type "
      + "order by year asc");
  ResultSet rs = stmt.executeQuery();

  Table<Integer, String, BigDecimal> table = HashBasedTable.create();

  int firstYear = 0;
  int lastYear = 0;

  while (rs.next()) {
    int year = rs.getInt(1);
    String type = rs.getString(2);
    BigDecimal total = rs.getBigDecimal(3);

    if (firstYear == 0) {
      firstYear = year;
    }
    lastYear = year;

    table.put(year, type, total);
  }

  writer.name("first_year").value(firstYear);

  for (String encType : table.columnKeySet()) {
    writer.name(encType).beginArray();

    for (int y = firstYear; y <= lastYear; y++) {
      BigDecimal count = table.get(y, encType);
      if (count == null) {
        count = BigDecimal.ZERO;
      }
      writer.value(count);
    }
    writer.endArray(); // encType
  }

  writer.endObject(); // costs
}
 
Example 18
Project: aliyun-maxcompute-data-collectors   File: TestBigDecimalExport.java   View Source Code Vote up 4 votes
private void runBigDecimalExport(String line)
    throws IOException, SQLException {
  FileSystem fs = FileSystem.get(getConf());
  Path tablePath = getTablePath();
  fs.mkdirs(tablePath);
  Path filePath = getDataFilePath();
  DataOutputStream stream = fs.create(filePath);
  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stream));
  writer.write(line);
  writer.close();
  String[] types =
    { "DECIMAL", "NUMERIC" };
  createTableWithColTypes(types, null);

  List<String> args = new ArrayList<String>();

  CommonArgs.addHadoopFlags(args);

  args.add("--table");
  args.add(getTableName());
  args.add("--export-dir");
  args.add(tablePath.toString());
  args.add("--connect");
  args.add(getConnectString());
  args.add("-m");
  args.add("1");

  runExport(args.toArray(new String[args.size()]));

  BigDecimal actual1 = null;
  BigDecimal actual2 = null;

  Connection conn = getConnection();
  try {
    PreparedStatement stmt = conn.prepareStatement("SELECT * FROM "
        + getTableName());
    try {
      ResultSet rs = stmt.executeQuery();
      try {
        rs.next();
        actual1 = rs.getBigDecimal(1);
        actual2 = rs.getBigDecimal(2);
      } finally {
        rs.close();
      }
    } finally {
      stmt.close();
    }
  } finally {
    conn.close();
  }

  BigDecimal expected1 = new BigDecimal("0.000001");
  BigDecimal expected2 = new BigDecimal("0.0000001");

  assertEquals(expected1, actual1);
  assertEquals(expected2, actual2);
}
 
Example 19
Project: tangyuan2   File: BigDecimalTypeHandler.java   View Source Code Vote up 4 votes
@Override
public BigDecimal getNullableResult(ResultSet rs, String columnName) throws SQLException {
	return rs.getBigDecimal(columnName);
}
 
Example 20
Project: tangyuan2   File: BigDecimalTypeHandler.java   View Source Code Vote up 4 votes
@Override
public BigDecimal getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
	return rs.getBigDecimal(columnIndex);
}