private int getFileId(Path filePath, Connection conn) throws SQLException {
        int fileId = readFileId(filePath, conn);
        if (fileId == -1) {
            Statement stmt = conn.createStatement();
            String insertFileSql = "insert into file (path, name) values ('" + filePath.getParent()
                    + "', '" + filePath.getFileName() + "');";
            stmt.executeUpdate(insertFileSql);
            stmt.close();

            fileId = readFileId(filePath, conn);
            if (fileId == -1) {
                throw new InternalError("Impossible to read the ID for the file " + filePath + " in database "
                        + databasePath);
            }

            stmt.close();
        }

        return fileId;
    }
private int getFileId ( Path filePath , Connection conn ) throws SQLException { int fileId = readFileId ( filePath , conn ) ; if ( fileId == - 1 ) { Statement stmt = conn . createStatement ( ) ; String insertFileSql = "insert into file (path, name) values ('" + filePath . getParent ( ) + "', '" + filePath . getFileName ( ) + "');" ; stmt . executeUpdate ( insertFileSql ) ; stmt . close ( ) ; fileId = readFileId ( filePath , conn ) ; if ( fileId == - 1 ) { throw new InternalError ( "Impossible to read the ID for the file " + filePath + " in database " + databasePath ) ; } stmt . close ( ) ; } return fileId ; }
Read file ID from the database. If it does not exits, then insert it to the database and return the file ID.

@param filePath  File to insert
@param conn      Database connection
@return          File ID in the database