Helper Helper - 1 month ago 20
Java Question

How to insert Big Integer in prepared statement java

I want to insert a Big integer value using prepared statement, i have one string variable called xid (41527820021925053)

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


I am new to this how to achieve this.

Answer

You can try

 preparedStatement = conn.prepareStatement(sql);
    preparedStatement.setObject(1,XOBJ);
    preparedStatement.setObject(2,YOBJ);
    preparedStatement.setBigDecimal(3, BigDecimal.valueOf(Long.parseLong(xid)));
    preparedStatement.setInt(4, 23);
    preparedStatement.executeUpdate();
    preparedStatement.close();