PostgreSQL JDBC Null String taken as a bytea

后端 未结 9 614
后悔当初
后悔当初 2020-12-10 02:59

If entity.getHistory() is null following code snippet:

(getEntityManager() returns spring injected EntityManager, database field history type is: text or varchar2(20

9条回答
  •  青春惊慌失措
    2020-12-10 03:14

    If you are willing to use the PreparedStatement class instead of Query:

    if (entity.getHistory() == null)
        stmt.setNull(6, Types.VARCHAR);
    else
        stmt.setString(6, entity.getHistory());
    

    (It is possible that using ?::text in your query string would also work, but I've never done it that way myself.)

提交回复
热议问题