简体   繁体   中英

How to use for loop to add new field into document index Lucene.

what i am trying to do is to use a for loop to add data from mySQL DB into my index document. An if loop is to ensure that only columns with data are added into the index document else it skips to the next line. In total, there are 6 columns named tag1 to tag6 with a some blank columns.

for (int i = 1; i < 6; i++) {   
            if (( result.getString("tag(i)")) != null) {
                                                document.add(new Field("tag(i)", result.getString("tag(i)"),Field.Store.YES,
                                            Field.Index.NOT_ANALYZED));
        }
    }

However, there appears to be an error. Can anyone tell me what is wrong or any advice to make it work? Thanks

Exception in thread "main" java.sql.SQLException: Column 'tag(i)' not found.

You dont have a column named "tag(i)". This says nothing about whether you have a column named "tag(1)" or "tag(2)", but you don't have column "tag(i)". Perhaps you are looking for something like:

result.getString("tag(" + i + ")")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM