java null 0,整数获取默认值0,其中Java中需要为NULL

My requirement looks simple, but I feel I'm doing something wrong in code.

All I need is to insert "null" in Oracle Database when nothing is passed from InputText field of UI.

PaymantSpecFormPage.xhtml

PaymentSpecVO.java

public class PaymentSpecVO extends BaseVO {

private Integer paymStartWk;

public Integer getPaymStartWk() {

return paymStartWk;

}

public void setPaymStartWk(Integer paymStartWk) {

this.paymStartWk = paymStartWk;

}

}

And in my DB Table

COLUMN_NAME DATA_TYPE NULLABLE DEFAULT_VALUE

------------ --------- -------- -------------

PAYM_START_WK NUMBER(4,0) Yes null

And when I enter nothing in inputText, then instead of null, 0 is getting entered in Table, which has different meaning in my business logic, please help me to do necessary code changes.

解决方案

And when I enter nothing in inputText, then instead of null, 0 is getting entered in table

This problem is recognizable as Tomcat's EL parser not taking into account that you're using Integer instead of int. You need to add the following VM argument to Tomcat startup options:

-Dorg.apache.el.parser.COERCE_TO_ZERO=false

See also:

It solved my half of problem, and now its storing null values, but while on retrieve it shows 0 again

This problem is recognizable as JDBC under the covers using ResultSet#getInt() instead of ResultSet#getObject(). This is however essentially a different problem than the first one. You didn't tell anything about how your database access layer is setup, so it's hard to point out a concrete solution.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值