Example usage for java.sql Types NULL

List of usage examples for java.sql Types NULL

Introduction

In this page you can find the example usage for java.sql Types NULL.

Prototype

int NULL

To view the source code for java.sql Types NULL.

Click Source Link

Document

The constant in the Java programming language that identifies the generic SQL value NULL.

Usage

From source file:com.cnd.greencube.server.dao.jdbc.JdbcDAO.java

@SuppressWarnings("rawtypes")
public void save(Object obj, String[] columns) throws Exception {
    // ???//  www . ja  va  2s  .c o  m
    Class clazz = obj.getClass();
    String tableName = getTableName(clazz);

    if (StringUtils.isEmpty(tableName))
        throw new SQLException("No @Table annotation in Class " + clazz.getName());
    List<Column2Property> setterColumnsNames = getColumnsFromObj(obj, columns);
    if (null == setterColumnsNames || setterColumnsNames.size() == 0)
        throw new SQLException("Column is nul, you must specified update columns.");

    StringBuffer sb = new StringBuffer("insert into " + tableName);
    sb.append(" ( ");
    int size = setterColumnsNames.size();
    Column2Property c;
    for (int i = 0; i < size; i++) {
        c = setterColumnsNames.get(i);
        if (i == 0)
            sb.append(c.columnName);
        else
            sb.append("," + c.columnName);
    }
    sb.append(" ) values ( ");
    for (int i = 0; i < size; i++) {
        c = setterColumnsNames.get(i);
        if (i == 0)
            sb.append("?");
        else
            sb.append(",?");
    }
    sb.append(" ) ");

    Connection conn = null;
    try {
        conn = getJdbcTemplate().getDataSource().getConnection();

        TableMetaManager tableManager = TableMetaManager.getInstance();
        Table t = tableManager.getTable(tableName);
        if (t == null) {
            _loadTable_(conn, tableName, clazz);
            t = tableManager.getTable(tableName);
        }

        if (conn.isClosed()) {
            throw new SQLException("Connection is closed!");
        }

        PreparedStatement st = conn.prepareStatement(sb.toString());
        for (int i = 1; i <= size; i++) {
            Column2Property column = setterColumnsNames.get(i - 1);
            if (obj == null) {
                st.setNull(i, java.sql.Types.NULL);
                continue;
            }

            Object value = MethodUtils.invokeMethod(obj, column.getterMethodName, null);
            if (value == null) {
                st.setNull(i, java.sql.Types.NULL);
                continue;
            }

            setColumnValue(st, column, t.getMeta(column.columnName), value, i);
        }

        st.execute();
    } finally {
        try {
            conn.close();
        } catch (Exception e) {
        }
    }
}

From source file:org.pentaho.di.jdbc.Support.java

/**
 * Get the JDBC type constant which matches the supplied Object type.
 *
 * @param value The object to analyse./*ww w .  j a va 2s .c  om*/
 * @return The JDBC type constant as an <code>int</code>.
 */
static int getJdbcType(Object value) {
    if (value == null) {
        return java.sql.Types.NULL;
    }

    return getJdbcType(value.getClass());
}

From source file:com.flexive.core.storage.genericSQL.GenericHierarchicalStorage.java

/**
 * Set a prepared statements values to <code>NULL</code> from startPos to endPos
 *
 * @param ps       prepared statement//from  ww  w. j  a  va 2  s. c  om
 * @param startPos start position
 * @param endPos   end position
 * @throws SQLException on errors
 */
protected static void clearPreparedStatement(PreparedStatement ps, int startPos, int endPos)
        throws SQLException {
    for (int i = startPos; i <= endPos; i++)
        ps.setNull(i, Types.NULL);
}

From source file:com.streamsets.pipeline.lib.jdbc.JdbcUtil.java

public Field resultToField(ResultSetMetaData md, ResultSet rs, int columnIndex, int maxClobSize,
        int maxBlobSize, DataType userSpecifiedType, UnknownTypeAction unknownTypeAction,
        boolean timestampToString) throws SQLException, IOException, StageException {
    Field field;/*w w  w  .ja v a  2 s .co m*/
    if (userSpecifiedType != DataType.USE_COLUMN_TYPE) {
        // If user specifies the data type, overwrite the column type returned by database.
        field = Field.create(Field.Type.valueOf(userSpecifiedType.getLabel()), rs.getObject(columnIndex));
    } else {
        // All types as of JDBC 2.0 are here:
        // https://docs.oracle.com/javase/8/docs/api/constant-values.html#java.sql.Types.ARRAY
        // Good source of recommended mappings is here:
        // http://www.cs.mun.ca/java-api-1.5/guide/jdbc/getstart/mapping.html
        switch (md.getColumnType(columnIndex)) {
        case Types.BIGINT:
            field = Field.create(Field.Type.LONG, rs.getObject(columnIndex));
            break;
        case Types.BINARY:
        case Types.LONGVARBINARY:
        case Types.VARBINARY:
            field = Field.create(Field.Type.BYTE_ARRAY, rs.getBytes(columnIndex));
            break;
        case Types.BIT:
        case Types.BOOLEAN:
            field = Field.create(Field.Type.BOOLEAN, rs.getObject(columnIndex));
            break;
        case Types.CHAR:
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.VARCHAR:
            field = Field.create(Field.Type.STRING, rs.getObject(columnIndex));
            break;
        case Types.CLOB:
        case Types.NCLOB:
            field = Field.create(Field.Type.STRING, getClobString(rs.getClob(columnIndex), maxClobSize));
            break;
        case Types.BLOB:
            field = Field.create(Field.Type.BYTE_ARRAY, getBlobBytes(rs.getBlob(columnIndex), maxBlobSize));
            break;
        case Types.DATE:
            field = Field.create(Field.Type.DATE, rs.getDate(columnIndex));
            break;
        case Types.DECIMAL:
        case Types.NUMERIC:
            field = Field.create(Field.Type.DECIMAL, rs.getBigDecimal(columnIndex));
            field.setAttribute(HeaderAttributeConstants.ATTR_SCALE,
                    String.valueOf(rs.getMetaData().getScale(columnIndex)));
            field.setAttribute(HeaderAttributeConstants.ATTR_PRECISION,
                    String.valueOf(rs.getMetaData().getPrecision(columnIndex)));
            break;
        case Types.DOUBLE:
            field = Field.create(Field.Type.DOUBLE, rs.getObject(columnIndex));
            break;
        case Types.FLOAT:
        case Types.REAL:
            field = Field.create(Field.Type.FLOAT, rs.getObject(columnIndex));
            break;
        case Types.INTEGER:
            field = Field.create(Field.Type.INTEGER, rs.getObject(columnIndex));
            break;
        case Types.ROWID:
            field = Field.create(Field.Type.STRING, rs.getRowId(columnIndex).toString());
            break;
        case Types.SMALLINT:
        case Types.TINYINT:
            field = Field.create(Field.Type.SHORT, rs.getObject(columnIndex));
            break;
        case Types.TIME:
            field = Field.create(Field.Type.TIME, rs.getObject(columnIndex));
            break;
        case Types.TIMESTAMP:
            final Timestamp timestamp = rs.getTimestamp(columnIndex);
            if (timestampToString) {
                field = Field.create(Field.Type.STRING, timestamp == null ? null : timestamp.toString());
            } else {
                field = Field.create(Field.Type.DATETIME, timestamp);
                if (timestamp != null) {
                    final long actualNanos = timestamp.getNanos() % NANOS_TO_MILLIS_ADJUSTMENT;
                    if (actualNanos > 0) {
                        field.setAttribute(FIELD_ATTRIBUTE_NANOSECONDS, String.valueOf(actualNanos));
                    }
                }
            }
            break;
        // Ugly hack until we can support LocalTime, LocalDate, LocalDateTime, etc.
        case Types.TIME_WITH_TIMEZONE:
            OffsetTime offsetTime = rs.getObject(columnIndex, OffsetTime.class);
            field = Field.create(Field.Type.TIME, Date.from(offsetTime.atDate(LocalDate.MIN).toInstant()));
            break;
        case Types.TIMESTAMP_WITH_TIMEZONE:
            OffsetDateTime offsetDateTime = rs.getObject(columnIndex, OffsetDateTime.class);
            field = Field.create(Field.Type.ZONED_DATETIME, offsetDateTime.toZonedDateTime());
            break;
        //case Types.REF_CURSOR: // JDK8 only
        case Types.SQLXML:
        case Types.STRUCT:
        case Types.ARRAY:
        case Types.DATALINK:
        case Types.DISTINCT:
        case Types.JAVA_OBJECT:
        case Types.NULL:
        case Types.OTHER:
        case Types.REF:
        default:
            if (unknownTypeAction == null) {
                return null;
            }
            switch (unknownTypeAction) {
            case STOP_PIPELINE:
                throw new StageException(JdbcErrors.JDBC_37, md.getColumnType(columnIndex),
                        md.getColumnLabel(columnIndex));
            case CONVERT_TO_STRING:
                Object value = rs.getObject(columnIndex);
                if (value != null) {
                    field = Field.create(Field.Type.STRING, rs.getObject(columnIndex).toString());
                } else {
                    field = Field.create(Field.Type.STRING, null);
                }
                break;
            default:
                throw new IllegalStateException("Unknown action: " + unknownTypeAction);
            }
        }
    }

    return field;
}

From source file:com.cnd.greencube.server.dao.jdbc.JdbcDAO.java

@SuppressWarnings("rawtypes")
public void update(Object obj, String[] columns) throws Exception {
    // ???/*from w ww  . j  a v a2  s.c  om*/
    Class clazz = obj.getClass();
    String tableName = getTableName(clazz);

    if (StringUtils.isEmpty(tableName))
        throw new SQLException("No @Table annotation in Class " + clazz.getName());
    List<Column2Property> setterColumnsNames = getColumnsFromObj(obj, columns);
    if (null == setterColumnsNames || setterColumnsNames.size() == 0)
        throw new SQLException("Column is nul, you must specified update columns.");

    StringBuffer sb = new StringBuffer("update " + tableName);
    sb.append(" set ");
    int size = setterColumnsNames.size();
    Column2Property c;
    for (int i = 0; i < size; i++) {
        c = setterColumnsNames.get(i);
        if (i == 0)
            sb.append(c.columnName + " = ?");
        else
            sb.append("," + c.columnName + " = ? ");
    }

    Connection conn = null;
    try {
        conn = getJdbcTemplate().getDataSource().getConnection();

        TableMetaManager tableManager = TableMetaManager.getInstance();
        Table t = tableManager.getTable(tableName);
        if (t == null) {
            _loadTable_(conn, tableName, clazz);
            t = tableManager.getTable(tableName);
        }

        sb.append(" where " + t.getIdColumnName() + " = ?");

        if (conn.isClosed()) {
            throw new SQLException("Connection is closed!");
        }
        PreparedStatement st = conn.prepareStatement(sb.toString());
        for (int i = 1; i <= size; i++) {
            Column2Property column = setterColumnsNames.get(i - 1);
            if (obj == null) {
                st.setNull(i, java.sql.Types.NULL);
                continue;
            }

            Object value = MethodUtils.invokeMethod(obj, column.getterMethodName, null);
            if (value == null) {
                st.setNull(i, java.sql.Types.NULL);
                continue;
            }

            setColumnValue(st, column, t.getMeta(column.columnName), value, i);
        }

        // ?ID
        Column2Property id = getIdFromObject(obj.getClass());
        Object idValue = MethodUtils.invokeMethod(obj, id.getterMethodName, null);
        setColumnValue(st, t.getIdColumnName(), t.getIdMetaData(), idValue, size + 1);

        st.execute();
    } finally {
        try {
            conn.close();
        } catch (Exception e) {
        }
    }
}

From source file:org.pentaho.di.jdbc.Support.java

/**
 * Get a String describing the supplied JDBC type constant.
 *
 * @param jdbcType The constant to be decoded.
 * @return The text decode of the type constant as a <code>String</code>.
 *//*from www . j  a  v  a2  s. c  o m*/
static String getJdbcTypeName(int jdbcType) {
    switch (jdbcType) {
    case java.sql.Types.ARRAY:
        return "ARRAY";
    case java.sql.Types.BIGINT:
        return "BIGINT";
    case java.sql.Types.BINARY:
        return "BINARY";
    case java.sql.Types.BIT:
        return "BIT";
    case java.sql.Types.BLOB:
        return "BLOB";
    case java.sql.Types.BOOLEAN:
        return "BOOLEAN";
    case java.sql.Types.CHAR:
        return "CHAR";
    case java.sql.Types.CLOB:
        return "CLOB";
    //            case JtdsStatement.DATALINK:       return "DATALINK";
    case java.sql.Types.DATE:
        return "DATE";
    case java.sql.Types.DECIMAL:
        return "DECIMAL";
    case java.sql.Types.DISTINCT:
        return "DISTINCT";
    case java.sql.Types.DOUBLE:
        return "DOUBLE";
    case java.sql.Types.FLOAT:
        return "FLOAT";
    case java.sql.Types.INTEGER:
        return "INTEGER";
    case java.sql.Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case java.sql.Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case java.sql.Types.LONGVARCHAR:
        return "LONGVARCHAR";
    case java.sql.Types.NULL:
        return "NULL";
    case java.sql.Types.NUMERIC:
        return "NUMERIC";
    case java.sql.Types.OTHER:
        return "OTHER";
    case java.sql.Types.REAL:
        return "REAL";
    case java.sql.Types.REF:
        return "REF";
    case java.sql.Types.SMALLINT:
        return "SMALLINT";
    case java.sql.Types.STRUCT:
        return "STRUCT";
    case java.sql.Types.TIME:
        return "TIME";
    case java.sql.Types.TIMESTAMP:
        return "TIMESTAMP";
    case java.sql.Types.TINYINT:
        return "TINYINT";
    case java.sql.Types.VARBINARY:
        return "VARBINARY";
    case java.sql.Types.VARCHAR:
        return "VARCHAR";
    default:
        return "ERROR";
    }
}

From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java

/**
 * Delete Metric data - maintenance cleanup function
 * //from  w w  w .  j a v a 2 s .co m
 * @param metricNamespace
 * @param startDate
 * @param endDate
 */
@Override
public void deleteMetricData(String metricNamespace, Date startDate, Date endDate) {
    Connection conn = null;
    CallableStatement stmt = null;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    try {
        Class.forName("net.sourceforge.jtds.jdbc.Driver");
        conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password);

        // Delete metric data
        stmt = conn.prepareCall("uspMetricData_Delete(?,?,?,?)");
        stmt.setString(1, metricNamespace);
        stmt.setNull(2, Types.NULL);

        if (startDate != null)
            stmt.setString(3, sdf.format(startDate));
        else
            stmt.setString(3, null);

        if (endDate != null)
            stmt.setString(4, sdf.format(endDate));
        else
            stmt.setString(4, null);

        stmt.execute();
    } catch (SQLException e) {
        this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage());
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage());
        e.printStackTrace();
    } finally {
        DbUtils.closeQuietly(stmt);
        DbUtils.closeQuietly(conn);
    }
}

From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java

public void testObject() throws SQLException {
    Statement stat = conn.createStatement();
    ResultSet rs;//from ww  w.  j  a  v  a 2 s .com
    stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
    stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
    PreparedStatement prep = conn
            .prepareStatement("SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? FROM TEST");
    prep.setObject(1, Boolean.TRUE);
    prep.setObject(2, "Abc");
    prep.setObject(3, new BigDecimal("10.2"));
    prep.setObject(4, new Byte((byte) 0xff));
    prep.setObject(5, new Short(Short.MAX_VALUE));
    prep.setObject(6, new Integer(Integer.MIN_VALUE));
    prep.setObject(7, new Long(Long.MAX_VALUE));
    prep.setObject(8, new Float(Float.MAX_VALUE));
    prep.setObject(9, new Double(Double.MAX_VALUE));
    prep.setObject(10, Date.valueOf("2001-02-03"));
    prep.setObject(11, Time.valueOf("04:05:06"));
    prep.setObject(12, Timestamp.valueOf("2001-02-03 04:05:06.123456789"));
    prep.setObject(13, new java.util.Date(Date.valueOf("2001-02-03").getTime()));
    prep.setObject(14, new byte[] { 10, 20, 30 });
    prep.setObject(15, new Character('a'), Types.OTHER);
    prep.setObject(16, "2001-01-02", Types.DATE);
    // converting to null seems strange...
    prep.setObject(17, "2001-01-02", Types.NULL);
    prep.setObject(18, "3.725", Types.DOUBLE);
    prep.setObject(19, "23:22:21", Types.TIME);
    prep.setObject(20, new java.math.BigInteger("12345"), Types.OTHER);
    rs = prep.executeQuery();
    rs.next();
    assertTrue(rs.getObject(1).equals(Boolean.TRUE));
    assertTrue(rs.getObject(2).equals("Abc"));
    assertTrue(rs.getObject(3).equals(new BigDecimal("10.2")));
    assertTrue(rs.getObject(4).equals((byte) 0xff));
    assertTrue(rs.getObject(5).equals(new Short(Short.MAX_VALUE)));
    assertTrue(rs.getObject(6).equals(new Integer(Integer.MIN_VALUE)));
    assertTrue(rs.getObject(7).equals(new Long(Long.MAX_VALUE)));
    assertTrue(rs.getObject(8).equals(new Float(Float.MAX_VALUE)));
    assertTrue(rs.getObject(9).equals(new Double(Double.MAX_VALUE)));
    assertTrue(rs.getObject(10).equals(Date.valueOf("2001-02-03")));
    assertEquals("04:05:06", rs.getObject(11).toString());
    assertTrue(rs.getObject(11).equals(Time.valueOf("04:05:06")));
    assertTrue(rs.getObject(12).equals(Timestamp.valueOf("2001-02-03 04:05:06.123456789")));
    assertTrue(rs.getObject(13).equals(Timestamp.valueOf("2001-02-03 00:00:00")));
    assertEquals(new byte[] { 10, 20, 30 }, (byte[]) rs.getObject(14));
    assertTrue(rs.getObject(15).equals('a'));
    assertTrue(rs.getObject(16).equals(Date.valueOf("2001-01-02")));
    assertTrue(rs.getObject(17) == null && rs.wasNull());
    assertTrue(rs.getObject(18).equals(new Double(3.725)));
    assertTrue(rs.getObject(19).equals(Time.valueOf("23:22:21")));
    assertTrue(rs.getObject(20).equals(new java.math.BigInteger("12345")));

    // } else if(x instanceof java.io.Reader) {
    // return session.createLob(Value.CLOB,
    // TypeConverter.getInputStream((java.io.Reader)x), 0);
    // } else if(x instanceof java.io.InputStream) {
    // return session.createLob(Value.BLOB, (java.io.InputStream)x, 0);
    // } else {
    // return ValueBytes.get(TypeConverter.serialize(x));

    stat.execute("DROP TABLE TEST");

}

From source file:it.fub.jardin.server.DbUtils.java

public int setObjects(final Integer resultsetId, final List<BaseModelData> records, String username)
        throws HiddenException {

    int result = 0;
    Connection connection = this.dbConnectionHandler.getConn();
    final String sep = ",";

    String tableName = null;//from   w  w w .  j av  a2  s.  co  m
    // String set = "";
    try {
        ResultSetMetaData metadata = this.dbProperties.getResultsetMetadata(connection, resultsetId);
        tableName = metadata.getTableName(1);
        connection.setAutoCommit(false);
        for (BaseModelData record : records) {
            String set = "";
            int columns = record.getPropertyNames().size();
            for (String property : record.getPropertyNames()) {
                set += "`" + property + "`=?" + sep;
            }
            set = set.substring(0, set.length() - sep.length());

            // String query =
            // "INSERT INTO `" + tableName + "` SET " + set
            // + " ON DUPLICATE KEY UPDATE " + set;
            String query = "INSERT INTO `" + tableName + "` SET " + set;

            PreparedStatement ps = (PreparedStatement) connection.prepareStatement(query);
            int i = 1;
            for (String property : record.getPropertyNames()) {
                Object value = record.get(property);
                if ((value != null) && (String.valueOf(value).length() > 0)) {
                    ps.setObject(i, record.get(property));
                    // ps.setObject(i + columns, record.get(property));
                } else {
                    ps.setNull(i, java.sql.Types.NULL);
                    // ps.setNull(i + columns, java.sql.Types.NULL);
                }
                i++;
            }
            // System.out.println(ps.toString());
            int num = ps.executeUpdate();
            if (num > 0) {
                String toLog = "INSERT (" + ps.toString() + ")";
                // Log.debug(toLog);
                JardinLogger.debug(username, toLog);
            }
            result += num;
        }
        connection.commit();
        connection.setAutoCommit(true);
    } catch (MySQLIntegrityConstraintViolationException ex) {
        try {
            connection.rollback();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            JardinLogger.debug(username, "Errore SQL: impossibile eseguire rollback transazione");
            e.printStackTrace();
        }
        String message = ex.getLocalizedMessage();
        String newMess = "";
        // Log.warn("Errore SQL", ex);
        if (ex.getErrorCode() == 1062) {
            // updateObjects(resultsetId, records);
            newMess = newMess.concat(ex.getErrorCode() + " - Errore!!! \n PRIMARY KEY DUPLICATA :\n" + message);
        } else if (ex.getErrorCode() == 1048) {
            newMess = newMess
                    .concat(ex.getErrorCode() + " - Errore!!! \n VINCOLO DI INTEGRITA' VIOLATO :\n" + message);
        } else if (ex.getErrorCode() == 1452) {
            newMess = newMess
                    .concat(ex.getErrorCode() + " - Errore!!! \n VINCOLO DI FOREIGN KEY VIOLATO :\n" + message);
        } else {
            newMess = ex.getErrorCode() + " - Errore!!! \n Problemi sui dati da salvare :\n" + message;
        }
        JardinLogger.debug(username, "Errore SQL: " + newMess);
        throw new HiddenException(newMess);

    } catch (Exception e) {
        try {
            JardinLogger.error(username, "Errore SQL: impossibile eseguire rollback transazione");
            connection.rollback();
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        // Log.warn("Errore SQL", e);
        throw new HiddenException("Errore durante il salvataggio delle modifiche:\n" + e.getLocalizedMessage());
    } finally {
        // JardinLogger.info("Records setted");
        this.dbConnectionHandler.closeConn(connection);
    }
    return result;
}

From source file:org.sleuthkit.autopsy.timeline.db.EventDB.java

/**
 * use transactions to update files/*from  w  w  w.j av  a2 s . c o m*/
 *
 * @param f
 * @param transaction
 */
void insertEvent(long time, EventType type, long datasourceID, long objID, Long artifactID,
        String fullDescription, String medDescription, String shortDescription, TskData.FileKnown known,
        Set<String> hashSetNames, List<? extends Tag> tags, EventTransaction transaction) {

    if (transaction.isClosed()) {
        throw new IllegalArgumentException("can't update database with closed transaction"); // NON-NLS
    }
    int typeNum = RootEventType.allTypes.indexOf(type);
    int superTypeNum = type.getSuperType().ordinal();

    DBLock.lock();
    try {

        //"INSERT INTO events (datasource_id,file_id ,artifact_id, time, sub_type, base_type, full_description, med_description, short_description, known_state, hashHit, tagged) " 
        insertRowStmt.clearParameters();
        insertRowStmt.setLong(1, datasourceID);
        insertRowStmt.setLong(2, objID);
        if (artifactID != null) {
            insertRowStmt.setLong(3, artifactID);
        } else {
            insertRowStmt.setNull(3, Types.NULL);
        }
        insertRowStmt.setLong(4, time);

        if (typeNum != -1) {
            insertRowStmt.setInt(5, typeNum);
        } else {
            insertRowStmt.setNull(5, Types.INTEGER);
        }

        insertRowStmt.setInt(6, superTypeNum);
        insertRowStmt.setString(7, fullDescription);
        insertRowStmt.setString(8, medDescription);
        insertRowStmt.setString(9, shortDescription);

        insertRowStmt.setByte(10,
                known == null ? TskData.FileKnown.UNKNOWN.getFileKnownValue() : known.getFileKnownValue());

        insertRowStmt.setInt(11, hashSetNames.isEmpty() ? 0 : 1);
        insertRowStmt.setInt(12, tags.isEmpty() ? 0 : 1);

        insertRowStmt.executeUpdate();

        try (ResultSet generatedKeys = insertRowStmt.getGeneratedKeys()) {
            while (generatedKeys.next()) {
                long eventID = generatedKeys.getLong("last_insert_rowid()"); //NON-NLS
                for (String name : hashSetNames) {

                    // "insert or ignore into hash_sets (hash_set_name)  values (?)"
                    insertHashSetStmt.setString(1, name);
                    insertHashSetStmt.executeUpdate();

                    //TODO: use nested select to get hash_set_id rather than seperate statement/query ?
                    //"select hash_set_id from hash_sets where hash_set_name = ?"
                    selectHashSetStmt.setString(1, name);
                    try (ResultSet rs = selectHashSetStmt.executeQuery()) {
                        while (rs.next()) {
                            int hashsetID = rs.getInt("hash_set_id"); //NON-NLS
                            //"insert or ignore into hash_set_hits (hash_set_id, obj_id) values (?,?)";
                            insertHashHitStmt.setInt(1, hashsetID);
                            insertHashHitStmt.setLong(2, eventID);
                            insertHashHitStmt.executeUpdate();
                            break;
                        }
                    }
                }
                for (Tag tag : tags) {
                    //could this be one insert?  is there a performance win?
                    insertTag(tag, eventID);
                }
                break;
            }
        }

    } catch (SQLException ex) {
        LOGGER.log(Level.SEVERE, "failed to insert event", ex); // NON-NLS
    } finally {
        DBLock.unlock();
    }
}