Welcome, guest! Login / Register - Why register?
[email protected] webmail now available. Want one? Go here.

Paste

Pasted as Plain Text by Kaz ( 9 years ago )
/**
  * Adds some record in BOOKS table
  * 
  * @param indexWriter
  *            the index writer
  */
 private void addIndex(IndexWriter indexWriter) throws CorruptIndexException, IOException {
  try {
   Connection connection = JDBCDatabaseUtil.getConnection();
   String query = "SELECT BOOK_ID, BOOK_NAME, BOOK_AUTHOR, BOOK_PUBLISHER FROM books";
   PreparedStatement pstmt = connection.prepareStatement(query);
   ResultSet resultSet = pstmt.executeQuery();
   while (resultSet.next()) {
    Document document = new Document();
    document.add(new Field("id", String.valueOf(resultSet.getInt(1)), Field.Store.YES, Field.Index.ANALYZED));
    document.add(new Field("name", String.valueOf(resultSet.getString(2)), Field.Store.YES, Field.Index.ANALYZED));
    document.add(new Field("author", String.valueOf(resultSet.getString(3)), Field.Store.YES, Field.Index.ANALYZED));
    document.add(new Field("publisher", String.valueOf(resultSet.getString(4)), Field.Store.YES, Field.Index.ANALYZED));
   
                                      indexWriter.addDocument(document);
            
                        }
                    indexWriter.close();    
            
  } catch (SQLException e) {
   e.printStackTrace();
  }
 }

 

Revise this Paste

Your Name: Code Language: