由于我的数据库有几千万条数据,每一条查询都会花费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();
}
}