java - How to escape from use PreparedStatement.setNull? -


i have big table in database. of fields may null.

i want escape use the:

preparedstatement.setnull(index, type.x) 

like:

if(obj.getsomadata() == null){   insertstmt.setnull(++i, java.sql.types.varchar); }else{   insertstmt.setstring(++i, obj.getsomadata()); } 

there's better , cleaner way this?

p.s.: i'm using postgresql.

the primary use case of setnull setting primitive types null, , handle edge cases driver can't know data types of parameters , needs explicitly instructed.

in cases should able use setstring(idx, null) (or setxxx of object type) fine.

to quote jdbc 4.2 section 13.2.2.4:

if java null passed of setter methods take java object, parameter set jdbc null.

an exception made 'untyped' null (eg using setobject), suggested maximum portability should use setnull or setobject takes type parameter not database support without type information.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -