PreparedStatement setNull(..)

后端 未结 5 1377
走了就别回头了
走了就别回头了 2020-11-28 06:32

Java PreparedStatement provides a possibility to explicitely set a Null value. This possibility is:

prepStmt.setNull(parameterIndex, Types.VARCHAR);
<         


        
5条回答
  •  星月不相逢
    2020-11-28 07:16

    preparedStatement.setNull(index, java.sql.Types.NULL);
    

    that should work for any type. Though in some cases failure happens on the server-side, like: for SQL:

    COALESCE(?, CURRENT_TIMESTAMP)
    

    Oracle 18XE fails with the wrong type: expected DATE, got STRING -- that is a perfectly valid failure;

    Bottom line: it is good to know the type if you call .setNull()

提交回复
热议问题