📄 firstcatalogtopane.java
字号:
package file2;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.text.*;
import java.io.*;
public class FirstCatalogToPane extends JPanel{
//声明数据库连接组件
private DBConnection con=null;
private File file=null;//声明所选择的文件
private String fileName;//声明所选择文件的文件名
private JFileChooser fileChooser;//声明目的文件
public FirstCatalogToPane(JFrame frame){
fileChooser=new JFileChooser();
int returnValue=fileChooser.showOpenDialog(frame);
if(returnValue==JFileChooser.APPROVE_OPTION){
con=new DBConnection();
file=fileChooser.getSelectedFile();
if(file==null){
JOptionPane.showMessageDialog(null, "导出文件不能为空,请您选择导出文件!", "提示", JOptionPane.ERROR_MESSAGE);
return;
}
fileName=file.getName();
JOptionPane.showMessageDialog(null, "正往文件"+fileName+"导出数据", "提示", JOptionPane.INFORMATION_MESSAGE);
}
int returnPara=saveTo(file);
if(returnPara==0){
JOptionPane.showMessageDialog(null, "往文件导出数据成功", "提示", JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null, "往文件导出数据失败", "提示", JOptionPane.ERROR_MESSAGE);
}
return;
}
public int saveTo(File file){
try{
BufferedWriter bw=new BufferedWriter(new FileWriter(file));
String strQuery="select First_name from First_Catalog";
ResultSet rs=con.executeSelect(strQuery);
bw.write("------------以下是所有的商品大类记录-------------");
bw.newLine();
bw.newLine();
bw.write("-------商品大类名称------");
bw.newLine();
bw.newLine();
while(rs.next()){
bw.write("-----"+rs.getString("First_name").trim()+"-----");
bw.newLine();
bw.newLine();
}
bw.close();
return 0;
}catch(IOException e){
//e.printStackTrace();
JOptionPane.showMessageDialog(null, "导出文件失败!", "提示", JOptionPane.ERROR_MESSAGE);
return 1;
}catch(SQLException e){
//e.printStackTrace();
JOptionPane.showMessageDialog(null, "导出文件失败!!", "提示", JOptionPane.ERROR_MESSAGE);
return 1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -