/**
@author yangenxiong
*
*/
class importTableChooser extends JFileChooser {
private MainFrame mainFrame;
private Database db;
public importTableChooser(MainFrame mainFrame, Database db) {
this.mainFrame = mainFrame;
this.db = db;
this.setFileSelectionMode(DIRECTORIES_ONLY);
}
public void approveSelection() {
File file = this.getSelectedFile();
if (file.isDirectory()) {
//用戶選擇了目錄
File targetFile = new File(file.getAbsolutePath() + File.separator +
this.db.getDatabaseName() + ".xls");
this.mainFrame.importTable();
} else {
this.mainFrame.importTable();
}
super.approveSelection();
}
}
差的太遠了,你只有選擇文件,importTable()的實現代碼沒有,也沒有任何解析excel的代碼
你可以用poi讀取excel然後循環插入數據庫
http://www.cnblogs.com/xwdreamer/archive/2012/02/22/2363152.html