由於我的數據庫有幾千萬條數據,每一條查詢都會花費0.5秒,但是10000條查詢需要半個多小時,所以希望有快速一點的方法,求各位大神指點,下面是我的函數。
/**
* 這是一個橫著的for循環,圖的縮放級別是13,11*10方格,不同區域到不同區域的上車點數量
*/
public static void CountListPointsOfOnetoOne()
{
ArrayList ListSql = new ArrayList();
double f_l_u_lon = 112.897715-0.012279;//首先區域的左上的經度
double f_l_u_lat = 28.249313-0.002519;//首先區域的左上的緯度
double lon_range = 0.01649; //0.014003/2;//經度區間0.007001
double lat_range = 0.0149787; //0.011176/2;//緯度區間
Connectjdbc connectjdbc = new Connectjdbc();
String sql = "";
for(int i=0;i<10;i++)
{
for(int j=0;j<11;j++)
{
double f_l_u_lon2 = (f_l_u_lon+lon_range); //首先區域的格子右下的經度
double f_l_u_lat2 = (f_l_u_lat-lat_range);//首先區域的格子右下的緯度
double s_l_u_lon = 112.897715-0.012279;//第二區域的左上的經度
double s_l_u_lat = 28.249313-0.002519;//第二區域的左上的緯度
for(int ii=0;ii<10;ii++)
{
for(int jj=0;jj<11;jj++)
{
double s_l_u_lon2 = (s_l_u_lon+lon_range); //第二區域的格子右下的經度
double s_l_u_lat2 = (s_l_u_lat-lat_range);//第二區域的格子右下的緯度
sql= "SELECT Count(ONTIME) FROM T_BUSINESSHISTORY where " +
" ONTIME between TO_DATE('2013-01-1 00:00:00','yyyy-mm-dd hh24-mi-ss') " +
" and TO_DATE('2013-1-31 23:59:59','yyyy-mm-dd hh24-mi-ss') " +
" and ONLON between "+ f_l_u_lon*3600000+" and "+f_l_u_lon2*3600000+" " +
" and ONLAT between "+ f_l_u_lat2*3600000+" and "+f_l_u_lat*3600000 +
" and OFFLON between "+ s_l_u_lon*3600000+" and "+s_l_u_lon2*3600000+" " +
" and OFFLAT between "+ s_l_u_lat2*3600000+" and "+s_l_u_lat*3600000 ;
ListSql.add(sql);
}
s_l_u_lon = 112.897715-0.012279;//左上的經度
s_l_u_lat = s_l_u_lat - lat_range;
}
// System.out.println(sql);
f_l_u_lon = f_l_u_lon + lon_range;
}
f_l_u_lon = 112.897715-0.012279;//左上的經度
f_l_u_lat = f_l_u_lat - lat_range;
}
ArrayList<String> ListCount = new ArrayList<String>();
try {
ListCount = connectjdbc.GetListCount(ListSql);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我用了一個存儲過程,效果不是很明顯,希望能用到的朋友,了解一下吧
CREATE OR REPLACE PROCEDURE T_BUSINESSHISTORY_SelectAreaToArea
(
l_u_lon IN varchar2,
l_u_lon2 IN varchar2,
l_u_lat2 IN varchar2,
l_u_lat IN varchar2,
shuliang out varchar2
)
AS
BEGIN
SELECT Count(ONTIME) into shuliang FROM T_BUSINESSHISTORY where ONTIME between TO_DATE('2013-01-1 00:00:00','yyyy-mm-dd hh24-mi-ss') and TO_DATE('2013-1-31 23:59:59','yyyy-mm-dd hh24-mi-ss') and ONLON between l_u_lon*3600000 and l_u_lon2*3600000 and ONLAT between l_u_lat2*3600000 and l_u_lat*3600000;
COMMIT;
END;
EXEC T_BUSINESSHISTORY_Select('112.878435','112.885436','28.231815','28.246794','shuliang');