Java SQL ResultSet BigDecimal Read getBigDecimalNotZero(ResultSet rs, String columnLabel)

Here you can find the source of getBigDecimalNotZero(ResultSet rs, String columnLabel)

Description

get Big Decimal Not Zero

License

Apache License

Declaration

public static BigDecimal getBigDecimalNotZero(ResultSet rs, String columnLabel) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {

    public static BigDecimal getBigDecimalNotZero(ResultSet rs, String columnLabel) throws SQLException {
        BigDecimal bigDecimal = rs.getBigDecimal(columnLabel);
        if (bigDecimal == null || bigDecimal.compareTo(BigDecimal.ZERO) == 0) {
            return null;
        } else {/*from  w w w. j  a  va2 s.  co m*/
            return bigDecimal;
        }
    }

    public static BigDecimal getBigDecimalNotZero(ResultSet rs, String columnLabel, int scale,
            RoundingMode roundingMode) throws SQLException {
        BigDecimal bigDecimal = rs.getBigDecimal(columnLabel);
        if (bigDecimal == null || bigDecimal.compareTo(BigDecimal.ZERO) == 0) {
            return null;
        } else {
            return bigDecimal.setScale(scale, roundingMode);
        }
    }

    public static BigDecimal getBigDecimal(ResultSet rs, String columnLabel) throws SQLException {
        BigDecimal bigDecimal = rs.getBigDecimal(columnLabel);
        if (bigDecimal != null) {
            return bigDecimal;
        } else {
            return null;
        }
    }

    public static BigDecimal getBigDecimal(ResultSet rs, String columnLabel, int scale, RoundingMode roundingMode)
            throws SQLException, ArithmeticException {
        BigDecimal bigDecimal = rs.getBigDecimal(columnLabel);
        if (bigDecimal != null) {
            return bigDecimal.setScale(scale, roundingMode);
        } else {
            return null;
        }
    }
}

Related

  1. getBigDecimal(ResultSet res, String name)
  2. getBigDecimal(ResultSet rs, String columnLabel)
  3. getBigDecimalArray(final ResultSet resultSet, final int index)