Re: Inserting JSON via Java PreparedStatment

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Inserting JSON via Java PreparedStatment
Дата
Msg-id CAKFQuwbZ-4_W2V0jSrrEkTRz62xJTum+Ld8QReyBXe_9g-A2mA@mail.gmail.com
обсуждение исходный текст
Ответ на Inserting JSON via Java PreparedStatment  (Curt Huffman <curt.huffman@gmail.com>)
Ответы Re: Inserting JSON via Java PreparedStatment  (rob stone <floriparob@gmail.com>)
Список pgsql-general

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.

В списке pgsql-general по дате отправления:

Предыдущее
От: MOLINA BRAVO FELIPE DE JESUS
Дата:
Сообщение: query reboot pgsql 9.5.1
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Inserting JSON via Java PreparedStatment