spring - How to pass BigInteger from java to Postgres? -


i need pass biginteger argument sql query. (on postgres 9.2) have code in dao:

    public list<personinfo> select(string id) {         biginteger bigintid = new biginteger(id);         jdbctemplate select = new jdbctemplate(datasource);         return select             .query("select * pe.supplier_input_data id = ?",                     new object[] { bigintid },                     new personrowmapper());     } 

i getting following exception:

{"error":"error invoking getpersoninfobyid.[org.springframework.jdbc.badsqlgrammarexception: preparedstatementcallback;  bad sql grammar [select * pe.supplier_input_data id = ?];  nested exception org.postgresql.util.psqlexception:  can't infer sql type use instance of java.math.biginteger.  use setobject() explicit types value specify type use.]"} 

the id of type bigint

tried pass plain string - throws type exception. googled message in exception - no relevant result. ideas?

support biginteger added in jdbc 4.1 (java 7), somehow had missed when wrote answer.

specifically section 3.1 overview of changes of jdbc 4.1 specification states:

  • additional mappings table b-4, mapping java object jdbc types
    [..]
    support added map java.lang.biginteger jdbc bigint.
  • additional mappings table b-5, performed setobject , setnull between java object types , target jdbc types
    [..]
    allow conversion of java.lang.biginteger char, varchar, longvarchar, , bigint.

i'm not sure how supported across drivers.

original answer

the jdbc specification not include support biginteger; either need use different datatype (eg bigdecimal scale 0), or find out if postgresql driver offers implementation specific way set biginteger value.


Comments

Popular posts from this blog

Eclipse formatter for java ending braces -

ruby - Nesting modules inside of a Rails eninge gem -

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -