How to insert big integer in Java preprocessing statement

I want to insert a large integer value using preprocessing statements. I have a string variable named XID (41527820021925053)

preparedStatement = conn.prepareStatement(sql);
    preparedStatement.setObject(1,XOBJ);
    preparedStatement.setObject(2,YOBJ);
    preparedStatement.setBigInteger(3,xid);
    preparedStatement.setInt(4,23);
    preparedStatement.executeUpdate();
    preparedStatement.close();

I am a novice, how to achieve this goal

Solution

Preparedstatement does not have a setbiginteger() method

Use one of the following methods:

>Setbigdecimal (3, new BigDecimal (XID)) > setlong (3, long. Parselong (XID)) if the value can fit in a long term > setstring (3, XID) let the jdbc driver convert the string for you

UPDATE

Using the following comment make by OP, the second option above (now highlighted) is the correct option, because PostgreSQL bigint is the same as Java long

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>