Java substring: 'string index out of range'

后端 未结 13 772
眼角桃花
眼角桃花 2020-12-03 10:24

I\'m guessing I\'m getting this error because the string is trying to substring a null value. But wouldn\'t the \".length() > 0\" part eliminate

13条回答
  •  情话喂你
    2020-12-03 10:34

    I would recommend apache commons lang. A one-liner takes care of the problem.

    pstmt2.setString(3, StringUtils.defaultIfEmpty(
        StringUtils.subString(itemdescription,0, 38), "_")); 
    

提交回复
热议问题