dav*_*ohn 3 java jdbc oracle11g
BIGINT我想使用 JDBC 从 Oracle 数据库获取值。
getBigInt()或者getBigInteger()不起作用getInt()。
这是代码片段:
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;
}
Run Code Online (Sandbox Code Playgroud)
表中的 emp_mob 列包含大整数值。
数据BIGINT类型是一个8字节的二进制数,这意味着匹配的Java类型是a long,所以使用getLong():
long mob = rs.getLong("emp_mob");
Run Code Online (Sandbox Code Playgroud)
如果该列是NULL-able 的,则使用 Java 类型Long,并wasNull()在调用后调用getLong():
Long mob = rs.getLong("emp_mob");
if (rs.wasNull())
mob = null;
Run Code Online (Sandbox Code Playgroud)
或者,如果您想要 Java BigInteger,请调用getBigDecimal()并转换它:
BigDecimal decimal = rs.getBigDecimal("emp_mob");
BigInteger mob = (decimal == null ? null : decimal.toBigInteger());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7147 次 |
| 最近记录: |