java JDBC中的数字溢出异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23404294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 22:50:49  来源:igfitidea点击:

Numeric overflow Exception in java JDBC

javaoraclejdbc

提问by kdubey007

This query returns a numeric overflow exception. Values from 1 to 14 are retrieved easily but bigger values (from 15 on) cannot be.

此查询返回数字溢出异常。可以轻松检索 1 到 14 之间的值,但不能检索更大的值(从 15 开始)。

I am using ORACLE XE. How do I fix this?

我正在使用 ORACLE XE。我该如何解决?

Here's my code:

这是我的代码:

pst=con.prepareStatement("Select * from student where sut_id like 'Kul7Dub514'");
rs=pst.executeQuery();
while(rs.next)
{
    smob.setText(Integer.toString(rs.getInt(15)));
    fmob.setText(Integer.toString(rs.getInt(16)));
    mmob.setText(Integer.toString(rs.getInt(17)));
    col.setText(rs.getString(18));
    address.setText(rs.getString(19));
}

Student's table:

学生表:

create table student ( stu_id varchar(10) primary key, stu_image Blob,
 stu_first_name varchar(20) not null,
 stu_middle_name varchar(20) not null,
 stu_last_name varchar(20) not null,
 fat_first_name varchar(20) not null,
 fat_middle_name varchar(20),
 fat_last_name varchar(20) not null,
 mot_first_name varchar(20),
 mot_middle_name varchar(20),
 mot_last_name varchar(20),
 dob Date,
 gender varchar(6),
 ac_yr varchar(10),
 mobno number(11),
 fatmob number(11),
 motmob number(11),
 edu_center varchar(50),
 address varchar(150) )

采纳答案by Scary Wombat

As the data in your DB is Number(11), this will not fit into an Integer.

由于您的数据库中的数据是Number(11),这不适合整数。

Try a Long and rs.getLong(15);

尝试一个 Long 和rs.getLong(15);

回答by ibre5041

Most likely you do not perform any mathematical operations with that "numbers". Since you do not treat them as numbers, but as identifiers you should use Java type BigDecimal. This is a type with is most similar to Oracle datatype NUMBER. Or you cal also use datatype provided by jdbc drivers oracle.sql.NUMBER.

很可能您没有使用该“数字”执行任何数学运算。由于您不将它们视为数字,而是将它们视为标识符,因此您应该使用 Java type BigDecimal。这是一种与 Oracle 数据类型最相似的类型NUMBER。或者您也可以使用 jdbc 驱动程序提供的数据类型oracle.sql.NUMBER