![java一次查詢幾十萬,幾百萬數(shù)據(jù)解決辦法.docx_第1頁](http://file.renrendoc.com/FileRoot1/2020-1/11/652928d2-be9d-450f-bd71-1729baaee2d0/652928d2-be9d-450f-bd71-1729baaee2d01.gif)
![java一次查詢幾十萬,幾百萬數(shù)據(jù)解決辦法.docx_第2頁](http://file.renrendoc.com/FileRoot1/2020-1/11/652928d2-be9d-450f-bd71-1729baaee2d0/652928d2-be9d-450f-bd71-1729baaee2d02.gif)
![java一次查詢幾十萬,幾百萬數(shù)據(jù)解決辦法.docx_第3頁](http://file.renrendoc.com/FileRoot1/2020-1/11/652928d2-be9d-450f-bd71-1729baaee2d0/652928d2-be9d-450f-bd71-1729baaee2d03.gif)
![java一次查詢幾十萬,幾百萬數(shù)據(jù)解決辦法.docx_第4頁](http://file.renrendoc.com/FileRoot1/2020-1/11/652928d2-be9d-450f-bd71-1729baaee2d0/652928d2-be9d-450f-bd71-1729baaee2d04.gif)
全文預覽已結(jié)束
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
java一次性查詢幾十萬,幾百萬數(shù)據(jù)解決辦法 分類: java數(shù)據(jù)庫2012-02-27 09:0816609人閱讀評論(27)收藏舉報java查詢一次性查詢幾十萬,幾百萬數(shù)據(jù)解決辦法很早的時候?qū)懝ぞ哂玫囊粋€辦法。 當時是用來把百萬數(shù)據(jù)打包 成rar文件。所以用了個笨辦法。 希望高手指導一下,有什么好方法沒有啊1、先批量查出所有數(shù)據(jù),例子中是一萬條一批。2、在查出數(shù)據(jù)之后把每次的數(shù)據(jù)按一定規(guī)則存入本地文件。3、獲取數(shù)據(jù)時,通過批次讀取,獲得大批量數(shù)據(jù)。此方法參見:/blog/static/175273432201191354043148/以下是查詢數(shù)據(jù)庫。按批次查詢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一次性查詢幾十萬,幾百萬數(shù)據(jù)解決辦法存入臨時文件之后,再用讀取大量數(shù)據(jù)文件方法。設(shè)置緩存大小BUFFER_SIZE ,Config.tempdatafile是文件地址來源博客/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);/ 來源博客/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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度事故車維修技術(shù)與人才輸出合同
- 如何進行有效的員工福利調(diào)研
- 2025年農(nóng)產(chǎn)品害蟲防治合作協(xié)議
- 2025年智能真空斷路器項目立項申請報告模范
- 2025年農(nóng)業(yè)服務(wù)項目申請報告模稿
- 2025年紫外固化材料項目立項申請報告
- 2025年角鋼項目提案報告模板
- 2025年腈類項目申請報告模板
- 2025年二手獨立產(chǎn)權(quán)房產(chǎn)轉(zhuǎn)讓協(xié)議書
- 2025年商業(yè)店鋪租賃轉(zhuǎn)讓協(xié)議
- 復產(chǎn)復工試題含答案
- 湖南省長沙市2023-2024學年八年級下學期入學考試英語試卷(附答案)
- 部編版語文三年級下冊第六單元大單元整體作業(yè)設(shè)計
- 售后服務(wù)經(jīng)理的競聘演講
- 臨床醫(yī)技科室年度運營發(fā)展報告
- 慢加急性肝衰竭護理查房課件
- 文件丟失應(yīng)急預案
- 從建設(shè)和諧社會角度思考治超限載(十)
- 幼兒園小班開學家長會課件
- 云南華葉投資公司2023年高校畢業(yè)生招聘1人筆試參考題庫(共500題)答案詳解版
- ABB電子時間繼電器CTMVS系列操作與安裝指南
評論
0/150
提交評論