I have a ERROR_MSG table which stores error messages with some ids. I want to insert error message if id is not present in table and if its present update error message. Inserting using below java JDBC code.
ID ERROR_MSG
1  ERR1
2  ERR2
3  ERR3
This is my code:
insertQry = "SQL";
Connection con = null;
PreparedStatement stmt = null;
try {
    con = getDataSource().getConnection();
    stmt = con.prepareStatement(insertQry);
    for(ListingAckNackData errorList: listOfListingERROR) {
        stmt.setLong(1, eqGlobalData.getSrcMsgId());
        stmt.setString(2, errorList.getGliId());
        if (null != errorList.getListingRevisionNo()) {
            stmt.setInt(3, errorList.getListingRevisionNo());
        } else {
            stmt.setNull(3, Types.NULL);
        }
        if (null != errorList.getErrorMessage()) {
            stmt.setString(4, errorList.getErrorMessage());
        } else {
            stmt.setNull(4, Types.NULL);
        }
        stmt.addBatch();
    }
    stmt.executeBatch();
}
 
     
    