DEVFYI - Developer Resource - FYI

How do I insert/update records with some of the columns having NULL value?

JDBC Interview Questions and Answers


(Continued from previous question...)

How do I insert/update records with some of the columns having NULL value?

Use either of the following PreparedStatement methods:
public void setNull(int parameterIndex, int sqlType) throws SQLException
public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException
These methods assume that the columns are nullable. In this case, you can also just omit the columns in an INSERT statement; they will be automatically assigned null values.

(Continued on next question...)

Other Interview Questions