Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jdbc prepared statement with oracle NUMBER type

I have a java application which sets up a jdbc connection to an Orcale database. I am attempting to insert data into the database but am confused when it comes to the oracle NUMBER type. I have three columns in my table which are of these types respectively.

NUMBER(38,0)
NUMBER(20,0)
NUMBER(16,0)

My first question is what type of java type should I put the data in, in order to use it in a prepared statement.

My second question is what set operation can I use in a prepared statement in order to insert the data.

Lets just assume we are working with NUMBER(38,0). Would I set the java type to a BigInteger? If I had an integer 1 would it be

 BigInteger one = new BigInteger(1);

Then in my preparedStatement it would be

 PreparedStatement pstmt = conn.prepareStatement("INSERT INTO TABLE(bigInt) VALUES(?)");
 pstmt.setLong(1, one);

This seems to not work, so I assume that this is not correct. Any help would be appreciated.

like image 972
medium Avatar asked Jun 27 '13 14:06

medium


1 Answers

setLong() cannot take a BigInteger. If you truly have values exceeding the range of long in your database, then you may need to use setBigDecimal(), as there is no setBigInteger(), and your variable would have to be of type BigDecimal. If long encompasses the range of values in your database, then just use long and setLong().

like image 118
GriffeyDog Avatar answered Nov 15 '22 01:11

GriffeyDog