如何改进搜索功能。?我已经写了一些代码来搜索something.The搜索花费了太多的时间。代码片段在这里,
我正在使用此方法从数据库中提取数据。
OracleConnection connection = null;
OraclePreparedStatement ptmst = null;
OracleResultSet rs = null;
OracleCallableStatement cstmt = null;
StringBuffer strBfr = new StringBuffer();
ArrayList myList = new ArrayList();
try
{
connection = (OracleConnection) TransactionScope.getConnection();
strBfr.append("select distinct .......... ");
ptmst = (OraclePreparedStatement)connection.prepareStatement(strBfr.toString());
rs = (OracleResultSet)ptmst.executeQuery();
while (rs.next())
{
HashMap hashItems = new HashMap();
hashItems.put("first",rs.getString(1));
hashItems.put("second",rs.getString(2));
myList.add(hashItems);
}
}
catch (Exception e) {
}
finally {
try {
if (ptmst != null) {
ptmst.close();
}
} catch (Exception e) {
}
try {
if (connection != null) {
TransactionScope.releaseConnection(connection);
}
} catch (Exception e) {
}
}
return myList; 在我的jsp中:
ArrayList getValues = new ArrayList();
getValues = //calling Method here.
for(int i=0; i < getValues.size();i++)
{
HashMap quoteSrch=(HashMap)allPOV.get(i);
first = (String)quoteSrch.get("first");
second = (String)quoteSrch.get("second");
}查询:
SELECT DISTINCT(mtl.segment1),
mtl.description ,
mtl.inventory_item_id ,
mtl.attribute16
FROM mtl_system_items_b mtl,
mtl_system_items_tl k
WHERE 1 =1
AND mtl.organization_id = ?
AND k.inventory_item_id = mtl.inventory_item_id
AND NVL(orderable_on_web_flag,'N')= 'Y'
AND NVL(web_status,'UNPUBLISHED') = 'PUBLISHED'
AND mtl.SEGMENT1 LIKE ? --Here is the search term发布于 2013-03-25 12:36:16
确保表中索引了organization_id、inventory_item_id,尤其是SEGMENT1。
你的查询是非常标准的,如果它不工作,那么你的数据库服务器似乎响应缓慢,这可能是由于许多原因,如低空间,低内存,缓慢的磁盘/读取等。
然后,您可以要求您的DBA/服务器管理员对此进行检查。
发布于 2013-03-25 12:46:21
首先,你需要找出真正的问题
一旦您确定它是DB查询,那么它就更像是一个DB问题。
在你分析了这个问题之后,你应该能够以不同的方式发布问题并期待答案。我不是一个DB的家伙,但我相信有人能够提供一些指示。
发布于 2013-03-25 13:00:39
调优必须完成:
TransactionScope.getConnection();正在进行无任何延迟的连接。您可以使用HashMap hashItems = new HashMap();while (rs.next()){ myList.add(rs.getString(1) +“分隔符”+ rs.getString(2));}
在jsp中使用
first = allPOV.get(i).split("delimter")[0];
second = allPOV.get(i).split("delimter")[1];以便您可以通过减少内存。
如果可能,请在查询中使用限制,并在SEGMENT1 link.上使用索引
https://stackoverflow.com/questions/15607476
复制相似问题