Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numeric overflow Exception in java JDBC

Tags:

java

oracle

jdbc

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

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

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) )
like image 910
kdubey007 Avatar asked May 01 '14 08:05

kdubey007


People also ask

How to resolve Numeric Overflow error?

Answers. This error occurs when the given numerical value exceeds the limit of the data type. We can resolve this error by providing values within the limit of the data type.

What is numeric overflow in Java?

java.sql.SQLException: Numeric Overflow This means that the numeric value that you're querying or inserting is larger than the DB field can hold. For example, trying to put 3000000000 in an Integer field while it can hold up max 2^32 (2147483647) will throw such an error.

How do you resolve ORA 01426 numeric overflow?

To resolve this issue, identify any such data issue, check if invalid numeric data can be removed/corrected from the source before loading to Oracle target. Work with DBA team and Oracle Support to identify which field is actually throwing an error. Pick the insert query. Append it to the values.

What causes SQL exception in Java?

When JDBC encounters an error during an interaction with a data source, it throws an instance of SQLException as opposed to Exception . (A data source in this context represents the database to which a Connection object is connected.)


1 Answers

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 which is most similar to Oracle datatype NUMBER. Or you can also use datatype provided by jdbc drivers oracle.sql.NUMBER.

like image 196
ibre5041 Avatar answered Sep 24 '22 22:09

ibre5041