JDBC prepared statement - make a token null So, I have an insert statement in a Java program I'm writing. Under some conditions, I want it to insert some values as null. However, before I can execute the statement, I have to set all of the tokens to values. How can I make it set something to null instead?

Edit:

Example:

    sql = "INSERT INTO DANIEL.UNIQUE_PHYSICIAN "
            + "(SOURCE_ID, ROOT_ID, SOURCE_TABLE, CONFIDENCE_IS_SAME,"
            + " IS_ROOT_PHYS, FIRST_NAME, LAST_NAME, POSTAL_CODE) VALUES (?, ?"
            + ", 'STI.PHYSICIAN', 1, 0, ?"
            + ", ?, ?)";


Sometimes, I want to insert nothing for POSTAL_CODE (for example)
You can use setNull():

preparedStatement.setNull(8, Types.VARCHAR);


Although I have seen drivers that do not properly support that, in that case simply try:  

preparedStatement.setString(8, null);