Search Postgresql Archives

Re: Inserting JSON via Java PreparedStatment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




pStmt.setString(11, dtlRec.toString());
pStmt.setObject(11, dtlRec.toString());

Which produce a different error:

Event JSON: {"New MbrID":29}

SQLException: ERROR: column "evtjson" is of type json but _expression_ is of type character varying

Hint: You will need to rewrite or cast the _expression_.


​Take the hint, literally.  You never did show the SQL but usually the least complex way to solve this is to indeed transfer the data as a string/text and then instruction PostgreSQL to convert (i.e., cast) it to json.

SELECT (?)::json;  <-- that ? parameter is seen as text; then you convert it.  The parentheses should be optional but I use them to emphasize the point.

​then​

pStmt.setString(1, dtlRec.toString());​

David J.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux