通过Java从MySQL获取大量记录 [英] Fetching large number of records from MySQL through Java

查看:77
本文介绍了通过Java从MySQL获取大量记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个MySQL表,服务器上的用户".它有28行和1百万条记录(它可能还会增加).我想从该表中获取所有行,对其进行一些操作,然后将它们添加到MongoDB中.我知道通过简单的从用户选择*"操作检索这些记录将花费大量时间.我一直在用Java,JDBC进行此操作. 因此,我从研究中得到的选择是:

There is a MySQL table, Users on a Server. It has 28 rows and 1 million records (It may increase as well). I want to fetch all rows from this table, do some manipulation on them and then want to add them to MongoDB. I know that it will take lots of time to retrieve these records through simple 'Select * from Users' operation. I have been doing this in Java, JDBC. So, the options I got from my research is:

选项1.执行批处理:我的计划是从表中获取总行数,即.从用户中选择count(*).然后,将读取大小设置为1000(setFetchSize(1000)).之后,我被困住了.我不知道我是否可以写这样的东西:

Option 1. Do batch processing : My plan was to get the total number of rows from the table, ie. select count(*) from users. Then, set a fetch size of say 1000 (setFetchSize(1000)). After that I was stuck. I did not know if I can write something like this:

    Connection conn = DriverManager.getConnection(connectionUrl, userName,passWord);
    Statement stmt =conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_READ_ONLY);
    String query="select * from users";
    ResultSet resultSet=stmt.executeQuery(query); 

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆