2011-11-11 46 views
2

我真的很苦惱,沒有出現在我的開發環境,只有一次在測試中部署的錯誤。即使是列,它也沒有編入索引。 PreparedStatement裏面

我正在使用準備好的Statement來連續運行30 000個查詢。查詢使用oracle模糊方法檢查字符串與數據庫內容的相似性。

檢查的列是索引的,但是,不知道爲什麼,它在一些迭代後隨機失敗,表示索引不存在。

我不明白髮生了什麼,因爲索引確實存在。我的方法永遠不會重建或刪除索引,所以沒有理由出現這個錯誤...

public List<EntryToCheck> checkEntriesOnSuspiciousElement(List<EntryToCheck> entries, int type,int score, int numresults, int percentage) throws Exception { 
    Connection connection = null; 
    PreparedStatement statementFirstName = null; 
    PreparedStatement statementLastname = null; 

    int finalScore = checkScore(score); 
    int finalNumResults = checkNumResults(numresults); 
    int finalPercentage = checkPercentage(percentage); 
    try { 
    connection = dataSource.getConnection(); 

    StringBuilder requestLastNameOnly = new StringBuilder("SELECT SE.ELEMENT_ID, SE.LASTNAME||' '||SE.FIRSTNAME AS ELEMENT, SCORE(1) AS SCORE "); 
    requestLastNameOnly.append("FROM BL_SUSPICIOUS_ELEMENT SE "); 
    requestLastNameOnly.append("WHERE CONTAINS(SE.LASTNAME, 'fuzzy({' || ? || '},' || ? || ',' || ? || ', weight)', 1)>? "); 
    requestLastNameOnly.append((type > 0 ? "AND SE.ELEMENT_TYPE_ID = ? " : " ")); 
    requestLastNameOnly.append("ORDER BY SCORE DESC"); 

    statementLastname = connection.prepareStatement(requestLastNameOnly.toString()); 
    for (EntryToCheck entryToCheck : entries) { 
      ResultSet rs; 
      boolean withFirstName = (entryToCheck.getEntryFirstname() != null && !entryToCheck.getEntryFirstname().equals("")); 
       statementLastname.setString(1, entryToCheck.getEntryLastname().replaceAll("'","''")); 
       statementLastname.setInt(2, finalScore); 
       statementLastname.setInt(3, finalNumResults); 
       statementLastname.setInt(4, finalPercentage); 

       if(type > 0){ 
        statementLastname.setInt(5, type); 
       } 
       System.out.println("Query LastName : " + entryToCheck.getEntryLastname().replaceAll("'","''")); 
       rs = statementLastname.executeQuery(); 

      while (rs.next()) { 

       Alert alert = new Alert(); 
       alert.setEntryToCheck(entryToCheck); 
       alert.setAlertStatus(new AlertStatus(new Integer(AlertStatusId.NEW))); 
       alert.setAlertDate(new Date()); 
       alert.setBlSuspiciousElement(new BlSuspiciousElement(new Integer(rs.getInt("ELEMENT_ID")))); 
       alert.setMatching(rs.getString("ELEMENT") + " (" + rs.getInt("SCORE") + "%)"); 
       entryToCheck.addAlert(alert); 
       } 

     } 
    } 
     catch (Exception e) { 
      e.printStackTrace(); 
      throw e; 
     } 
     finally { 
      DAOUtils.closeConnection(connection, statementLastname); 
     } 

     return entries; 
} 

真的不知道該看什麼?

謝謝!

˚F

回答

1

我從來沒有使用甲骨文文字表格,但我的建議是: 確保沒有其他人同時執行上表DDL語句。 另外,請確保您的索引是上下文索引。

0

爲您想要應用搜索的列創建索引

.............................. ..........

CREATE INDEX 「MTU219」。 「SEARCHFILTER」 ON 「BL_SUSPICIOUS_ELEMENT」( 「LASTNAME」) INDEXTYPE IS 「CTXSYS」。 「上下文」 的參數(「存儲CTXSYS.ST_MTED_NORMAL SYNC (ON COMMIT)');

..........................................

相關問題