Handling large records in a Java EE application

前端 未结 3 761
悲哀的现实
悲哀的现实 2020-12-15 14:37

There is a table phonenumbers with two columns: id, and number. There are about half a million entries in the table. Data

3条回答
  •  没有蜡笔的小新
    2020-12-15 15:29

    If using Mysql 5.1+, I would simply use the proprietary syntax to dump the file somewhere and stream it in a Servlet response.

    SELECT a,b,a+b INTO OUTFILE '/tmp/result.txt'
      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
      LINES TERMINATED BY '\n'
      FROM test_table;
    

    http://dev.mysql.com/doc/refman/5.1/en/select.html

    For so many records, if you still want to use JDBC, you may try the following:

    • fetch the number of records fetch few records( using a query limit ) and write them
    • if you reach the number of records in a chunk, you fetch another one until you reach the maximum number of records

提交回复
热议问题