java中list查询很慢问题_数据库查询很快,代码查询很慢
直接在客户端上查询速度很快,但是到了代码中速度慢了很多,数据量在100万左右这是查询代码:List result = new ArrayList<>();String sql = "SELECT * FROM (SELECT KEYWORDS FROM KEYWORD_PERSONAL_HEAT WHERE USER_ID = '"+userId+"' AND KEYWORDS LIK
直接在客户端上查询速度很快,但是到了代码中速度慢了很多,数据量在100万左右
这是查询代码:
List result = new ArrayList<>();
String sql = "SELECT * FROM (SELECT KEYWORDS FROM KEYWORD_PERSONAL_HEAT WHERE USER_ID = '"+userId+"' AND KEYWORDS LIKE '%"+keyword+"%' GROUP BY KEYWORDS ORDER BY max(TIMES) DESC) WHERE ROWNUM <="+rowNum;
List searchResult = JdbcUtils.findBySql(this.getEntityManager(), sql);
for(Map map:searchResult){
result.add((String) map.get("KEYWORDS"));
}
这是底层查询代码:
public static List findBySql(EntityManager entityManager,String sql){
List result=new ArrayList();
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
try{
conn=openConn(entityManager);
pstmt=openPstmt(conn,sql);
ResultSetMetaData rsmd=pstmt.getMetaData();
rs=openRs(pstmt);
while(rs.next()){
Map data=new HashMap();
for(int i=1;i<=rsmd.getColumnCount();i++){
String columnName=rsmd.getColumnName(i);
data.put(columnName,rs.getObject(columnName));
}
result.add(data);
}
}catch (SQLException e){
e.printStackTrace();
}finally {
closeConn(rs,pstmt,conn);
}
return result;
}
更多推荐
所有评论(0)