谁帮我查下苹果手机的苹果官网查激活时间间跟维修时间,讯列号F2LV13QAGRXH

Java实现从数据库导出大量数据记录并保存到文件的方法
作者:5iasp
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了Java实现从数据库导出大量数据记录并保存到文件的方法,涉及Java针对数据库的读取及文件写入等操作技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了Java实现从数据库导出大量数据记录并保存到文件的方法。分享给大家供大家参考,具体如下:
数据库脚本:
-- Table "t_test" DDL
CREATE TABLE `t_test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
`createTime` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
package com.yanek.
import java.io.BufferedR
import java.io.F
import java.io.FileOutputS
import java.io.FileR
import java.io.IOE
import java.io.OutputStreamW
import java.sql.C
import java.sql.DriverM
import java.sql.PreparedS
import java.sql.ResultS
import java.sql.SQLE
import java.sql.S
public class TestDB {
public static void main(String[] args) {
Test(); // 生成测试数据
//System.out.println(readText("/opt/id.txt"));
* 导出数据
public static void Exp() {
Connection Conn=
Class.forName("com.mysql.jdbc.Driver").newInstance();
String jdbcUrl = "jdbc:mysql://127.0.0.1:3306/testcms?characterEncoding=GBK";
String jdbcUsername = "root";
String jdbcPassword = "root";
Conn = DriverManager.getConnection(jdbcUrl, jdbcUsername, jdbcPassword);
System.out.println("conn"+Conn);
Exp(Conn);
} catch (SQLException e) {
e.printStackTrace();
catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public static void Exp(int startid) {
Connection Conn=
Class.forName("com.mysql.jdbc.Driver").newInstance();
String jdbcUrl = "jdbc:mysql://127.0.0.1:3306/testcms?characterEncoding=GBK";
String jdbcUsername = "root";
String jdbcPassword = "root";
Conn = DriverManager.getConnection(jdbcUrl, jdbcUsername, jdbcPassword);
System.out.println("conn"+Conn);
Exp(Conn,startid);
} catch (SQLException e) {
e.printStackTrace();
catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
* 导出从startid开始的数据
* @param conn
* @param start_id
public static void Exp(Connection conn,int start_id) {
int counter = 0;
int startid=start_
boolean flag =
while (flag) {
String Sql = "SELECT * FROM t_test WHERE id&"
+ startid + " order by id asc LIMIT 50";
System.out.println("sql===" + Sql);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(Sql);
while (rs.next()) {
int id = rs.getInt("id");
String title = rs.getString("title");
counter++;
writeContent(counter+"--id--"+id+"--title-"+title+"\r\n", "/opt/","log.txt",true);
System.out.println("i="+counter+"--id--"+id+"--title-"+title);
rs.close();
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
writeContent(""+startid, "/opt/","id.txt",false);
* 导出一小时内的数据
* @param conn
public static void Exp(Connection conn) {
int counter = 0;
//一小时内的数据
Long timestamp = System.currentTimeMillis() - (60 * 60 * 1000);
boolean flag =
while (flag) {
String Sql = "SELECT * FROM t_test WHERE createTime&"
+ timestamp + " LIMIT 50";
System.out.println("sql===" + Sql);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(Sql);
while (rs.next()) {
int id = rs.getInt("id");
String title = rs.getString("title");
Long lastmodifytime = rs.getLong("createTime");
timestamp =
counter++;
System.out.println("i="+counter+"--id--"+id+"--title-"+title);
rs.close();
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
public static void Test() {
Connection Conn=
Class.forName("com.mysql.jdbc.Driver").newInstance();
String jdbcUrl = "jdbc:mysql://127.0.0.1:3306/testcms?characterEncoding=GBK";
String jdbcUsername = "root";
String jdbcPassword = "root";
Conn = DriverManager.getConnection(jdbcUrl, jdbcUsername, jdbcPassword);
System.out.println("conn"+Conn);
for(int i=1;i&=10000;i++)
add(Conn,"testTitle"+i+"-"+System.currentTimeMillis());
} catch (SQLException e) {
e.printStackTrace();
catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public static void add(Connection conn,String title)
PreparedStatement pstmt =
String insert_sql = "insert into t_test(title,createTime) values (?,?)";
System.out.println("sql="+insert_sql);
pstmt = conn.prepareStatement(insert_sql);
pstmt.setString(1,title);
pstmt.setLong(2,System.currentTimeMillis());
int ret = pstmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
* 写入内容到文件
* @param number
* @param filename
public static boolean writeContent(String c, String dirname,String filename,boolean isAppend) {
File f=new File(dirname);
if (!f.exists())
f.mkdirs();
FileOutputStream fos = new FileOutputStream( dirname+File.separator+filename,isAppend);
OutputStreamWriter writer = new OutputStreamWriter(fos);
writer.write(c);
writer.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
* 从文件读取内容
* @param filename
public static String readText(String filename) {
String content = "";
File file = new File(filename);
if (file.exists()) {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String str = "";
String newline = "";
while ((str = br.readLine()) != null) {
content += newline +
newline = "\n";
br.close();
fr.close();
} catch (IOException e) {
e.printStackTrace();
基本思想: 就是通过记录开始记录id,执行多次sql来处理. 由于大数据量所以不能使用一条sql语句来输出.否则会内存不足导致错误.
主要用途: 可以使用在做接口开发时,给第三方提供数据增量输出的场景使用.
希望本文所述对大家Java程序设计有所帮助。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具(求助)怎样在文本框获取数据,添加到数据库中?给下代码,好好研究_java吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:590,602贴子:
(求助)怎样在文本框获取数据,添加到数据库中?给下代码,好好研究收藏
package Limport java.awt.*;import java.awt.event.*;import javax.swing.*;public class zhuce extends JFrame{&&&&& JFrame frm=new JFrame("读者注册");&&&&& JPanel pnl = new JPanel(new GridLayout(1, 2)); // 创建面板pnl&&&&& Label lab=new Label("姓名:"),lab2=new Label("学号:"),lab3=new Label("年龄:"),&&&&& lab4=new Label("分院:"),lab5=new Label("专业:"),lab6=new Label("班级:"),&&&&& lab7=new Label("读者注册");&&&&& TextField tx1=new TextField(""),tx2=new TextField(""),tx3=new TextField(""),&&&&& tx4=new TextField(""),tx5=new TextField(),tx6=new TextField("");&&&&& public zhuce(String title){&&&&&&&&& Button a1=new Button("确定"),a2=new Button("取消");&&&&&&&&&&&& frm.setLayout(null); // 取消窗口的默认版面设置&&&&&&&&&&&& frm.setSize(300, 300);&&&&&&&&&&&& frm.setVisible(true);&&&&&&&&&&&& //frm.setResizable(true); // 将窗口设置为固定大小&&&&&&&&&&&& lab.setBounds(10, 40, 50, 20);&&&&&&&&&&&& lab2.setBounds(10, 70, 50, 20);&&&&&&&&&&&& lab3.setBounds(10, 100,50,20 );&&&&&&&&&&&& lab4.setBounds(10,130,50,20);&&&&&&&&&&&& lab5.setBounds(10, 160, 50, 20);&&&&&&&&&&&& lab6.setBounds(10, 190, 50, 20);&&&&&&&&&&&& lab.setFocusable(false);&&&&&&&&&&&& lab2.setFocusable(false);&&&&&&&&&&&& lab3.setFocusable(false);&&&&&&&&&&&& lab4.setFocusable(false);&&&&&&&&&&&& lab5.setFocusable(false);&&&&&&&&&&&& lab6.setFocusable(false);&&&&&&&&&&&&&&&&&&&&&&&& tx1.setBounds(60, 40, 160, 20);&&&&&&&&&&&& tx2.setBounds(60, 70, 160, 20);
神牛摄影器材--为专业摄影者打造,你值得拥有!
&&&&&&&&&&&& tx3.setBounds(60, 100, 160, 20);&&&&&&&&&&&& tx4.setBounds(60, 130, 160, 20);&&&&&&&&&&&& tx5.setBounds(60, 160, 160, 20);&&&&&&&&&&&& tx6.setBounds(60, 190, 160, 20);&&&&&&&&&&&& pnl.setBounds(100,210,80,40);// 设置pnl置于窗口内&&&&&&&&&&&& pnl.add(a1);&&&&&&&&&&&& pnl.add(a2);&&&&&&&&&&&& a2.addActionListener(new ActionListener(){&&&&&&&&&&&&&&&& public void actionPerformed(ActionEvent io){&&&&&&&&&&&&&&&&&&&& frm.setVisible(false);&&&&&&&&&&&&&&&& }&&&&&&&&&&&& });&&&&&&&&&&&& frm.add(tx1);&&&&&&&&&&&& frm.add(tx2);&&&&&&&&&&&& frm.add(tx3);&&&&&&&&&&&& frm.add(tx4);&&&&&&&&&&&& frm.add(tx5);&&&&&&&&&&&& frm.add(tx6);&&&&&&&&&&&& frm.add(lab);&&&&&&&&&&&& frm.add(lab2);&&&&&&&&&&&& frm.add(lab3);&&&&&&&&&&&& frm.add(lab4);&&&&&&&&&&&& frm.add(lab5);&&&&&&&&&&&& frm.add(lab6);// 将面板放进窗口中&&&&&&&&&&&& frm.add(pnl);&&&&&&&&&&&& Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();&&&&&&&&&&&& // 将显示窗口置于屏幕中央&&&&&&&&&&&& frm.setLocation((scrSize.width - frm.getSize().width) / 2,&&&&&&&&&&&&&&&&&&&& (scrSize.height - frm.getSize().height) / 2);&&&&& }&&&&& /**&&&&& *
args&&&&& */&&&& /*public static void main(String[] args) {&&&&&&&& // TODO Auto-generated method stub&&&&&&&& zhuce a=new zhuce("");&&&& }*/&&&&&&&&}
马上就是要填志愿了,怎么办呢,我想学软件开发,又不知道老校区名流怎么样啊,听说很不错,不知道真的还是假的……
每一个文本框都是一个对象,TextFiled t1=new TextField();试试t1.text。类似有这样的方法。
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或

我要回帖

更多关于 苹果激活时间查询 的文章

 

随机推荐