即使它是列,也不会对列编制索引。 PreparedStatement里面

时间:2011-11-11 14:46:07

标签: sql oracle indexing prepared-statement

我真的很难解决我的开发环境中没有出现的错误,只有在测试中部署过。

我正在使用准备好的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

2 个答案:

答案 0 :(得分:1)

我从未使用过Oracle文本表,但我的建议是: 确保没有其他人同时在表上执行DDL语句。 另外,请确保您拥有的索引是上下文索引。

答案 1 :(得分:0)

为要应用搜索的列创建索引

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

创建索引“MTU219”。“搜索过程”“BL_SUSPICIOUS_ELEMENT”(“LASTNAME”)    INDEXTYPE是“CTXSYS”。“上下文”参数('存储CTXSYS.ST_MTED_NORMAL SYNC(ON COMMIT)');

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