JSP虚拟主机,jsp空间,java空间,java虚拟空间JSP虚拟主机,jsp空间,java空间,java虚拟空间

从网络数据库中下载数据,备份到文本文件中



作者:    文章来源:
发布日期:2007年01月21日
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.URL;
import java.sql.*;
import java.net.*;
class Window extends Frame implements ActionListener
{
TextArea text;
Panel panel;
TextField year;
TextField qihao;
StringBuffer text1;
Button button1;
BufferedWriter out;
ResultSet rs;
Connection cn;
String fname;
String[] fenbu;
String qisu;
String yearnum;
Choice choice1;
int fenbusu;
Window()
{
super("test!");
setLayout(new BorderLayout());
setBackground(Color.cyan);
setBounds(150,150,300,120);
setVisible(true);
text=new TextArea();
button1=new Button("确定");
year=new TextField("2003",5);
qihao=new TextField(5);
panel=new Panel();
panel.add(new Label("选择分部:"));
choice1=new Choice();
choice1.addItem("北京");
choice1.addItem("成都");
choice1.addItem("上海");
choice1.addItem("广州");
choice1.addItem("全部");
panel.add(choice1);
panel.add(new Label("输入年份:"));
panel.add(year);
panel.add(new Label("输入期号:"));
panel.add(qihao);
panel.add(button1);
add("North",panel);
add(text,"Center");
button1.addActionListener(this);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
qisu=qihao.getText().trim();
yearnum=year.getText().trim();
if(e.getSource()==button1)
{
if(choice1.getSelectedIndex()==0)
{
fname=("beijing.txt");
text.setText("beginning!!!!");
text1=new StringBuffer();
try{
ListData("lbeijing");
ListData("lheilongjiang");
ListData("ljilin");
ListData("lhenan");
ListData("lliaoning");
text1=new StringBuffer();
cn.close();

}
catch(SQLException eee){}
catch(IOException ie){}
text.setText("finished!!!!!");
}
else if(choice1.getSelectedIndex()==1)
{
fname=("chendu.txt");
text.setText("beginning!!!!!!");
text1=new StringBuffer();
try{
ListData("lchongqing");
ListData("lhubei");
ListData("lsichuan");
ListData("lxinjiang");
ListData("lguizhou");
ListData("lyunnan");
ListData("lshanxiq");
ListData("lgansu");
ListData("lshanxij");
text1=new StringBuffer();
cn.close();

}
catch(SQLException eee){}
catch(IOException ie){}
text.setText("finished!!!!!!!!!!");
}
else if(choice1.getSelectedIndex()==2)
{
text1=new StringBuffer();
text.setText("beginning!!!!!!!!!");
fname=("shanghai.txt");
try
{
ListData("lshanghai");
ListData("ljiangsu");
ListData("lshandong");
ListData("lzhejiang");
ListData("lanhui");
text1=new StringBuffer();
cn.close();
}
catch(SQLException eee){}
catch(IOException ie){}
text.setText("finished!!!!!!!!");
}
else if(choice1.getSelectedIndex()==3)
{
text1=new StringBuffer();
text.setText("beginning!!!!!!!!!");
fname=("guangdong.txt");
try{
ListData("lguangdong");
ListData("lshenzhen");
ListData("lfujian");
ListData("lguangxi");
ListData("lhunan");
text1=new StringBuffer();
cn.close();
}
catch(SQLException eee){}
catch(IOException ie){}
text.setText("finished!!!!!!!!!");
}
else if(choice1.getSelectedIndex()==4)
{
text1=new StringBuffer();
text.setText("beginning!!!!!!!!!");
fname=(qisu+".txt");
try{
ListData("lbeijing");
ListData("lheilongjiang");
ListData("ljilin");
ListData("lhenan");
ListData("lliaoning");
ListData("lchongqing");
ListData("lhubei");
ListData("lsichuan");
ListData("lxinjiang");
ListData("lguizhou");
ListData("lyunnan");
ListData("lshanxiq");
ListData("lgansu");
ListData("lshanxij");
ListData("lshanghai");
ListData("ljiangsu");
ListData("lshandong");
ListData("lzhejiang");
ListData("lanhui");

ListData("lguangdong");
ListData("lshenzhen");
ListData("lfujian");
ListData("lguangxi");
ListData("lhunan");
text1=new StringBuffer();
cn.close();
}
catch(SQLException eee){}
catch(IOException ie){}
text.setText("finished!!!!!!!!!");
}
}
}
public void ListData(String fb) throws SQLException,IOException
{
String lfb=fb;
String txt=new String("");

try{
Class.forName("org.gjt.mm.mysql.Driver");
}catch(ClassNotFoundException e){}
cn=DriverManager.getConnection("jdbc:mysql://172.143.41.216:3306/fxbdb","username","password");
Statement st=cn.createStatement();
rs=st.executeQuery("select * from "+lfb+" where issuenumber="+qisu+" and issueyear="+yearnum);
while(rs.next()){
text1.append(rs.getString(2)+"|"+rs.getString(3)+"|"+rs.getString(4)+"|"+rs.getString(5)+"|"+rs.getString(6)+"|"+rs.getString(7)+"|"+rs.getString(8)+"|"+rs.getString(9)+"|"+rs.getString(10)+"|"+rs.getString(11)+"|"+rs.getString(12)+"|"+rs.getString(13)+"|"+rs.getString(14)+"|"+rs.getString(18)+"|"+" ");
}

txt=text1.toString();
try{
out=new BufferedWriter(new FileWriter(fname));
}
catch(FileNotFoundException p)
{}
try{
out.write(txt,0,txt.length());
out.flush();
}
catch(IOException exp)
{
System.out.println("have problem!");
}
}



}
public class DownData
{
public static void main(String args[])
{
Window window=new Window();
window.pack();
}
}
Copyright © 2002-2012 JSPCN.net. All rights reserved.
JSP中文网    备案号:粤ICP备09171188号
成都恒海科技发展有限公司    成都市一环路南二段6号新瑞楼三楼8号