java一次查詢(xún)幾十萬(wàn),幾百萬(wàn)數(shù)據(jù)解決辦法.docx_第1頁(yè)
java一次查詢(xún)幾十萬(wàn),幾百萬(wàn)數(shù)據(jù)解決辦法.docx_第2頁(yè)
java一次查詢(xún)幾十萬(wàn),幾百萬(wàn)數(shù)據(jù)解決辦法.docx_第3頁(yè)
java一次查詢(xún)幾十萬(wàn),幾百萬(wàn)數(shù)據(jù)解決辦法.docx_第4頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

java一次性查詢(xún)幾十萬(wàn),幾百萬(wàn)數(shù)據(jù)解決辦法 分類(lèi): java數(shù)據(jù)庫(kù)2012-02-27 09:0816609人閱讀評(píng)論(27)收藏舉報(bào)java查詢(xún)一次性查詢(xún)幾十萬(wàn),幾百萬(wàn)數(shù)據(jù)解決辦法很早的時(shí)候?qū)懝ぞ哂玫囊粋€(gè)辦法。 當(dāng)時(shí)是用來(lái)把百萬(wàn)數(shù)據(jù)打包 成rar文件。所以用了個(gè)笨辦法。 希望高手指導(dǎo)一下,有什么好方法沒(méi)有啊1、先批量查出所有數(shù)據(jù),例子中是一萬(wàn)條一批。2、在查出數(shù)據(jù)之后把每次的數(shù)據(jù)按一定規(guī)則存入本地文件。3、獲取數(shù)據(jù)時(shí),通過(guò)批次讀取,獲得大批量數(shù)據(jù)。此方法參見(jiàn):/blog/static/175273432201191354043148/以下是查詢(xún)數(shù)據(jù)庫(kù)。按批次查詢(xún)public static void getMonthDataList() ResultSet rs = null;Statement stat = null;Connection conn = null;List list = new ArrayList();try conn = createConnection();if(conn!=null)SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd);SimpleDateFormat timesdf = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);String nowDate = sdf.format(new Date();Config.lasttimetext = timesdf.format(new Date();String lastDate = sdf.format(CreateData.addDaysForDate(new Date(), 30);stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);int lastrow = 0;int datanum = 0;String countsql = SELECT count(a.id) FROM trip_special_flight a + where a.dpt_date = to_date(+nowDate+,yyyy-mm-dd) +and a.dpt_date +lastrow+ order by a.get_time desc;rs = stat.executeQuery(countsql);while (rs.next() datanum = rs.getInt(1);int onerun = 10000;int runnum = datanum%onerun=0?(datanum/onerun):(datanum/onerun)+1;for(int r =0;r= to_date(+nowDate+,yyyy-mm-dd) +and a.dpt_date +lastrow;stat.setMaxRows(onerun);stat.setFetchSize(1000);rs = stat.executeQuery(sql);String text = ;int i = 1;while (rs.next() text += rs.getString(2)+|+rs.getString(3)+|+rs.getDate(4)+|+rs.getString(5)+|+rs.getString(6)+|+rs.getString(7)+|+rs.getString(8)+|;if(i%1000=0)FileUtil.appendToFile(Config.tempdatafile, text);text = ;i+;if(text.length()10)FileUtil.appendToFile(Config.tempdatafile, text);lastrow+=onerun; catch (Exception e) e.printStackTrace(); finally closeAll(rs, stat, conn);-java一次性查詢(xún)幾十萬(wàn),幾百萬(wàn)數(shù)據(jù)解決辦法存入臨時(shí)文件之后,再用讀取大量數(shù)據(jù)文件方法。設(shè)置緩存大小BUFFER_SIZE ,Config.tempdatafile是文件地址來(lái)源博客/blog/static/175273432201191354043148/package com.yjf.util;import java.io.File;import java.io.RandomAccessFile;import java.nio.MappedByteBuffer;import java.nio.channels.FileChannel;public class Test public static void main(String args) throws Exception final int BUFFER_SIZE = 0x300000; / 緩沖區(qū)為3MFile f = new File(Config.tempdatafile);/ 來(lái)源博客/blog/static/175273432201191354043148/int len = 0;Long start = System.currentTimeMillis();for (int z = 8; z 0; z-) MappedByteBuffer inputBuffer = new RandomAccessFile(f, r).getChannel().map(FileChannel.MapMode.READ_ONLY,f.length() * (z-1) / 8, f.length() * 1 / 8);byte dst = new byteBUFFER_SIZE;/ 每次讀出3M的內(nèi)容for (int offset = 0; offset = BUFFER_SIZE) for (int i = 0; i BUFFER_SIZE; i+)dsti = inputBuffer.get(offset + i); else for (int i = 0; i inputBuffer.capacity() - offset; i+)dsti = inputBuffer.get(offset + i);int length = (inputBuffer.capacity() % BUFFER_SIZE = 0) ? BUFFER_SIZE: inputBuffer.capacity() % BUFFER_SIZE;len += new String(dst, 0, length).length();System.out.println(new String(dst, 0, len

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論