I want to get a BIGINT
value from Oracle database using JDBC.
getBigInt()
or getBigInteger()
does not work like getInt()
.
Here is the code snippet:
public List<Employee> getAllEmployees()
{
List<Employee> employeeList = new ArrayList<Employee>();
try
{
//typical jdbc coding
Connection conn = DBUtil.getConnection();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM employee1");
while(rs.next())
{
Employee employee = new Employee(rs.getString("emp_id"), rs.getString("name"), rs.getBigInt("emp_mob"));
employeeList.add(employee);
}
DBUtil.closeConnection(conn); //close connection
}
catch(Exception e)
{
e.printStackTrace();
}
return employeeList;
}
emp_mob column in the table contains big integer values.
The BIGINT
data type is an 8-byte binary number, which means that the matching Java type is a long
, so use getLong()
:
long mob = rs.getLong("emp_mob");
If the column is NULL
-able, use Java type Long
, and call wasNull()
after calling getLong()
:
Long mob = rs.getLong("emp_mob");
if (rs.wasNull())
mob = null;
Alternatively, if you want a Java BigInteger
, call getBigDecimal()
and convert it:
BigDecimal decimal = rs.getBigDecimal("emp_mob");
BigInteger mob = (decimal == null ? null : decimal.toBigInteger());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With