导入导出,是数据库的一种专用命令。这里的数据库指的是软件方面的所有与之有关的数据库。
不同数据库对于导入导出的要求不同。
package zjexec.util; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io.Serializable; import java.sql.Connection; import java.util.Date; import java.util.Vector; import java.util.prefs.Preferences; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.filechooser.FileNameExtensionFilter; import org.apache.log4j.Logger; import zjexec.bean.common.Schema; import zjexec.bean.dialect.AbsDialect; import zjexec.bean.jframe.ComboxItem; import zjexec.bean.jframe.DBTableFrame; import zj.io.util.FileUtil; import zj.jdbc.bean.DBInfo; import zj.jdbc.util.JdbcUtil; import zj.serverTimeout.util.ServiceConnect; /** * * @author zhangjun * */ public class SchemaFrameUtil implements Serializable { private static final long serialVersionUID = 1L; private transient static final Logger log = Logger.getLogger(SchemaFrameUtil.class); private JFrame jframe = null; /** * btn1:测试源数据源连接 btn2:测试目标数据源连接 btn3:导出指定表 btn4:导入指定表 btn6:打开*.DDL btn18:DDL保存... btn20:DML浏览... btn21:DML保存... execBtn:开始执行... closeBtn:关闭 **/ private JButton btn1, btn2, btn3, btn4, btn6, btn18, btn20, btn21, execBtn, closeBtn; /** * jtf3:源ConnectionURL值 jtf4:源UserName jtf5:源Password jtf6:open-DDL文件 jtf13:目标ConnectionURL值 jtf14:目标UserName jtf15:目标Password jtf18:save-DDL文件 jlb20:open-DML文件 jlb21:save-DML文件 */ private JTextField jtf3, jtf4, jtf5, jtf6, jtf13, jtf14, jtf15, jtf18, jtf20, jtf21; private JLabel jlb1, jlb2, jlb3, jlb4, jlb5, jlb6, jlb7, jlb8, jlb9, jlb10, jlb11, jlb13, jlb14, jlb15, jlb16, jlb17, jlb18, jlb20, jlb21, jlb22, jlb23; private int linex = 30; private int liney1 = 10, liney2 = 50, liney3 = 90, liney4 = 130, liney5 = 170, liney6 = 210, liney7 = 250, liney8 = 290, liney9 = 330, liney10 = 370, liney11 = 410, liney12 = 450, liney13 = 490; /** jcb1:导出DDL-SQL,jcb2:导出DML-SQL,jcb3:多个dml-sql文件 **/ private JCheckBox jcb1, jcb2, jcb3; /** * select_jlb1:操作类型("请选择", "0:数据源导入", "1:DDL文件导入","2:DML文件导入","3:DDL文件导出","4:DML文件导出") select_jlb2:源DriverTemplate类型值 select_jlb9:目标数据源DDL select_jlb10:目标数据源DML select_jlb12:目标DriverTemplate类型值 select_jlb23 :导出DB文件格式方言 */ private JComboBox select_jlb1, select_jlb2, select_jlb9, select_jlb10, select_jlb12, select_jlb23; /** * checkbox_jlb1:选择 private JCheckBox checkbox_jcb1; radio_jrb1:DDL操作 radio_jrb2:DML操作 private JRadioButton radio_jrb1, radio_jrb2; */ private String line = "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"; private Connection conn; private String absDialect; private String title = "多数据库之间表操作-张军(手机:15656856396,QQ:360901061)制作"; /** 测试源数据源连接 **/ private static final String btn1Text = "测试源数据源连接"; /** 测试目标数据源连接 **/ private static final String btn2Text = "测试目标数据源连接"; /** 导出指定表 **/ private static final String btn3Text = "导出指定表"; /** 导入指定表 **/ private static final String btn4Text = "导入指定表"; /** 打开*.DDL **/ private static final String btn6Text = "打开*.DDL"; /** 保存DDL文件 **/ private static final String jlb18Text = "保存DDL文件"; /** 操作类型 **/ private static final String jlb1Text = "操作类型"; // TODO d /** 目标DML操作 **/ private static final String jlb10Text = "目标DML操作"; /** DriverTemplate **/ private static final String jlb11Text = "驱动模板"; /** ConnectionURL **/ private static final String jlb13Text = "连接URL"; /** UserName **/ private static final String jlb14Text = "用户名"; /** Password **/ private static final String jlb15Text = "密码"; /** 开始执行... **/ private static final String execBtnText = "开始执行..."; /** 关闭 **/ private static final String closeBtnText = "关闭"; /** 请选择 **/ private static final String selectDefaultText = "请选择"; /** 导出DB文件格式方言 **/ private static final String jlb23Text = "导出DB文件格式方言"; /** DriverTemplate **/ private static final String jlb2Text = "驱动模板"; /** ConnectionURL **/ private static final String jlb3Text = "连接URL"; /** UserName **/ private static final String jlb4Text = "用户名"; /** Password **/ private static final String jlb5Text = "密码"; /** 导出DDL-SQL **/ private static final String jcb1Text = "导出DDL-SQL"; /** 导出DML-SQL **/ private static final String jcb2Text = "导出DML-SQL"; /** 导出DML-SQL **/ private static final String jcb3Text = "多个SQL文件"; /** 选择DDL文件 **/ private static final String jlb6Text = "选择DDL文件"; /** 保存*.DDL **/ private static final String btn18Text = "保存*.DDL"; /** 选择DML文件 **/ private static final String jlb20Text = "选择DML文件"; /** 打开*.DML **/ private static final String btn20Text = "打开*.DML"; /** 保存DML文件 **/ private static final String jlb21Text = "保存DML文件"; /** 保存*.DML **/ private static final String btn21Text = "保存*.DML"; /** 目标DDL操作 **/ private static final String jlb9Text = "目标DDL操作"; // /****/ // private static final String = ; // /****/ // private static final String = ; // /****/ // private static final String = ; // /****/ // private static final String = ; /** * 禁用源数据源 */ private void disabledSrcDataSource() { this.select_jlb2.setEnabled(false); this.jtf3.setEditable(false); this.jtf4.setEditable(false); this.jtf5.setEditable(false); this.btn1.setEnabled(false); this.btn3.setEnabled(false); // this.select_jlb2.setSelectedIndex(0); // this.jtf5.setText(""); // this.jtf3.setText(""); // this.jtf4.setText(""); } /** * 启用源数据源 */ private void enabledSrcDataSource() { this.select_jlb2.setEnabled(true); if (!"".equals(((ComboxItem) select_jlb2.getSelectedItem()).value)) { this.jtf3.setEditable(true); this.jtf4.setEditable(true); this.jtf5.setEditable(true); } this.btn1.setEnabled(true); if (otherFrameExport == null) { this.btn3.setEnabled(true); } } /** * 禁用目标数据源 */ private void disabledDescDataSource() { this.select_jlb12.setEnabled(false); this.jtf13.setEditable(false); this.jtf14.setEditable(false); this.jtf15.setEditable(false); this.btn2.setEnabled(false); this.btn4.setEnabled(false); // this.select_jlb12.setSelectedIndex(0); // this.jtf13.setText(""); // this.jtf14.setText(""); // this.jtf15.setText(""); } /** * 启用目标数据源 */ private void enabledDescDataSource() { this.select_jlb12.setEnabled(true); if (!"".equals(((ComboxItem) select_jlb12.getSelectedItem()).value)) { this.jtf13.setEditable(true); this.jtf14.setEditable(true); this.jtf15.setEditable(true); } this.btn2.setEnabled(true); if (otherFrameImport == null) { this.btn4.setEnabled(true); } } /** * 禁用DDL/DML单选/选择框 */ private void disabledDescDDLDML() { this.select_jlb9.setEnabled(false); this.select_jlb10.setEnabled(false); // this.select_jlb9.setSelectedIndex(0); // this.select_jlb10.setSelectedIndex(0); } /** * 通过DDL/DML单选判断禁用DDL */ private void disabledDescDDLByRadio() { this.select_jlb9.setEnabled(false); this.select_jlb10.setEnabled(true); // this.select_jlb9.setSelectedIndex(0); } /** * 通过DDL/DML单选判断禁用DML */ private void disabledDescDMLByRadio() { this.select_jlb9.setEnabled(true); this.select_jlb10.setEnabled(false); // this.select_jlb10.setSelectedIndex(0); } /** * 禁用DDL文件 */ private void disabledDDLFile() { this.jtf6.setEditable(false); this.btn6.setEnabled(false); this.jtf18.setEditable(false); this.btn18.setEnabled(false); this.jcb1.setEnabled(false); this.jcb2.setEnabled(false); // this.jtf6.setText(""); // this.jtf18.setText(""); disabledSqlFileType(); } /** * 启用open-DDL文件 */ private void enableOpenDDLFile() { this.jtf6.setEditable(true); this.btn6.setEnabled(true); } /** * 启用save-DDL文件 */ private void enableSaveDDLFile() { this.jtf18.setEditable(true); this.btn18.setEnabled(true); this.jcb1.setEnabled(true); } /** * 禁用DML文件 */ private void disabledDMLFile() { this.jtf20.setEditable(false); this.btn20.setEnabled(false); this.jtf21.setEditable(false); this.btn21.setEnabled(false); // this.jtf20.setText(""); // this.jtf21.setText(""); this.jcb1.setEnabled(false); } /** * 启用open-DML文件 */ private void enableOpenDMLFile() { this.jtf20.setEditable(true); this.btn20.setEnabled(true); } /** * 启用save-DML文件 */ private void enableSaveDMLFile() { this.jtf21.setEditable(true); this.btn21.setEnabled(true); this.jcb2.setEnabled(true); } /** * 禁用共通 */ private void disabled() { this.select_jlb23.setEnabled(false); } /** * 启用共通 */ private void enable() { this.select_jlb23.setEnabled(true); } /** * 禁用导出sql文件类型 */ private void disabledSqlFileType() { this.jcb3.setEnabled(false); } /** * 启用导出sql文件类型 */ private void enableSqlFileType() { this.jcb3.setEnabled(true); } // select_jlb1.setEditable(true);//combobox设为可编辑 /** * 主窗口 */ public void setFrame() { jframe = new JFrame(title); addEventHandler(); jframe.setLayout(null); setComboxItems(); // 源数据源判断********************************************* jlb1 = new JLabel(jlb1Text); jlb1.setBounds(linex + 5, liney1, 105, 30); jframe.add(jlb1); select_jlb1.setBounds(linex + 115, liney1, 105, 30); jframe.add(select_jlb1); btn1 = new JButton(btn1Text); btn1.setBounds(linex + 225, liney1, 150, 30); jframe.add(btn1); btn3 = new JButton(btn3Text); btn3.setBounds(linex + 380, liney1, 120, 30); jframe.add(btn3); btn2 = new JButton(btn2Text); btn2.setBounds(linex + 505, liney1, 150, 30); jframe.add(btn2); btn4 = new JButton(btn4Text); btn4.setBounds(linex + 660, liney1, 120, 30); jframe.add(btn4); jlb23 = new JLabel(jlb23Text); jlb23.setBounds(linex + 785, liney1, 125, 30); jframe.add(jlb23); select_jlb23.setBounds(linex + 915, liney1, 120, 30); jframe.add(select_jlb23); // ********************************************* jlb8 = new JLabel("-----------------------------------------------------------------------------------------------------------------------源数据库配置开始-----------------------------------------------------------------------------------------------------------------------"); jlb8.setBounds(linex + 5, liney2, 1080, 30); jframe.add(jlb8); // 源数据源********************************************* jlb2 = new JLabel(jlb2Text); jlb2.setBounds(linex + 5, liney3, 105, 30); jframe.add(jlb2); select_jlb2.setBounds(linex + 115, liney3, 105, 30); jframe.add(select_jlb2); jlb3 = new JLabel(jlb3Text); jlb3.setBounds(linex + 225, liney3, 105, 30); jframe.add(jlb3); jtf3 = new JTextField(); jtf3.setBounds(linex + 335, liney3, 305, 30); jframe.add(jtf3); jlb4 = new JLabel(jlb4Text); jlb4.setBounds(linex + 645, liney3, 105, 30); jframe.add(jlb4); jtf4 = new JTextField(); jtf4.setBounds(linex + 755, liney3, 105, 30); jframe.add(jtf4); jlb5 = new JLabel(jlb5Text); jlb5.setBounds(linex + 865, liney3, 105, 30); jframe.add(jlb5); jtf5 = new JPasswordField(); jtf5.setBounds(linex + 975, liney3, 105, 30); jframe.add(jtf5); // DDL文件********************************************* jlb7 = new JLabel("-----------------------------------------------------------------------------------------------------------------------源数据库配置结束-----------------------------------------------------------------------------------------------------------------------"); jlb7.setBounds(linex + 5, liney4, 1080, 30); jframe.add(jlb7); // ********************************************* jcb1 = new JCheckBox(jcb1Text); jcb1.setBounds(linex + 5, liney5, 120, 30); jframe.add(jcb1); jcb2 = new JCheckBox(jcb2Text); jcb2.setBounds(linex + 130, liney5, 120, 30); jframe.add(jcb2); jcb3 = new JCheckBox(jcb3Text); jcb3.setBounds(linex + 255, liney5, 120, 30); jframe.add(jcb3); jlb6 = new JLabel(jlb6Text); jlb6.setBounds(linex + 5, liney6, 105, 30); jframe.add(jlb6); jtf6 = new JTextField(); jtf6.setBounds(linex + 115, liney6, 305, 30); jframe.add(jtf6); btn6 = new JButton(btn6Text); btn6.setBounds(linex + 425, liney6, 100, 30); jframe.add(btn6); jlb18 = new JLabel(jlb18Text); jlb18.setBounds(linex + 530, liney6, 105, 30); jframe.add(jlb18); jtf18 = new JTextField(); jtf18.setBounds(linex + 640, liney6, 305, 30); jframe.add(jtf18); btn18 = new JButton(btn18Text); btn18.setBounds(linex + 950, liney6, 100, 30); jframe.add(btn18); // ********************************************* // jlb19 = new JLabel(line); // jlb19.setBounds(linex + 5, liney6, 1080, 30); // jframe.add(jlb19); // DML文件********************************************* jlb20 = new JLabel(jlb20Text); jlb20.setBounds(linex + 5, liney7, 105, 30); jframe.add(jlb20); jtf20 = new JTextField(); jtf20.setBounds(linex + 115, liney7, 305, 30); jframe.add(jtf20); btn20 = new JButton(btn20Text); btn20.setBounds(linex + 425, liney7, 100, 30); jframe.add(btn20); jlb21 = new JLabel(jlb21Text); jlb21.setBounds(linex + 530, liney7, 105, 30); jframe.add(jlb21); jtf21 = new JTextField(); jtf21.setBounds(linex + 640, liney7, 305, 30); jframe.add(jtf21); btn21 = new JButton(btn21Text); btn21.setBounds(linex + 950, liney7, 100, 30); jframe.add(btn21); // ********************************************* jlb22 = new JLabel(line); jlb22.setBounds(linex + 5, liney8, 1080, 30); jframe.add(jlb22); // 目标数据源操作********************************************* jlb9 = new JLabel(jlb9Text); jlb9.setBounds(linex + 5, liney9, 105, 30); jframe.add(jlb9); // ButtonGroup bg = new ButtonGroup(); // radio_jrb1 = new JRadioButton("DDL"); // radio_jrb1.setBounds(linex+115, liney9, 50, 30); // bg.add(radio_jrb1); // radio_jrb2 = new JRadioButton("DML"); // radio_jrb2.setBounds(linex+170, liney9, 50, 30); // bg.add(radio_jrb2); // jframe.add(radio_jrb1); // jframe.add(radio_jrb2); select_jlb9.setBounds(linex + 115, liney9, 105, 30); jframe.add(select_jlb9); jlb10 = new JLabel(jlb10Text); jlb10.setBounds(linex + 225, liney9, 105, 30); jframe.add(jlb10); select_jlb10.setBounds(linex + 335, liney9, 105, 30); jframe.add(select_jlb10); // ********************************************* jlb16 = new JLabel("-----------------------------------------------------------------------------------------------------------------------目标数据库配置开始-----------------------------------------------------------------------------------------------------------------------"); jlb16.setBounds(linex + 5, liney10, 1080, 30); jframe.add(jlb16); // 目标数据源********************************************* jlb11 = new JLabel(jlb11Text); jlb11.setBounds(linex + 5, liney11, 105, 30); jframe.add(jlb11); select_jlb12.setBounds(linex + 115, liney11, 105, 30); jframe.add(select_jlb12); jlb13 = new JLabel(jlb13Text); jlb13.setBounds(linex + 225, liney11, 105, 30); jframe.add(jlb13); jtf13 = new JTextField(); jtf13.setBounds(linex + 335, liney11, 305, 30); jframe.add(jtf13); jlb14 = new JLabel(jlb14Text); jlb14.setBounds(linex + 645, liney11, 105, 30); jframe.add(jlb14); jtf14 = new JTextField(); jtf14.setBounds(linex + 755, liney11, 105, 30); jframe.add(jtf14); jlb15 = new JLabel(jlb15Text); jlb15.setBounds(linex + 865, liney11, 105, 30); jframe.add(jlb15); jtf15 = new JPasswordField(); jtf15.setBounds(linex + 975, liney11, 105, 30); jframe.add(jtf15); // ********************************************* jlb17 = new JLabel("-----------------------------------------------------------------------------------------------------------------------目标数据库配置结束-----------------------------------------------------------------------------------------------------------------------"); jlb17.setBounds(linex + 5, liney12, 1080, 30); jframe.add(jlb17); // 操作********************************************* execBtn = new JButton(execBtnText); execBtn.setBounds(linex + 330, liney13, 100, 30); jframe.add(execBtn); closeBtn = new JButton(closeBtnText); closeBtn.setBounds(linex + 560, liney13, 120, 30); jframe.add(closeBtn); // 添加监听********************************************* btn1.addActionListener(new ExecCommondActionEvent()); btn2.addActionListener(new ExecCommondActionEvent()); btn3.addActionListener(new ExecCommondActionEvent()); btn4.addActionListener(new ExecCommondActionEvent()); btn6.addActionListener(new ExecCommondActionEvent()); btn18.addActionListener(new ExecCommondActionEvent()); btn20.addActionListener(new ExecCommondActionEvent()); btn21.addActionListener(new ExecCommondActionEvent()); execBtn.addActionListener(new ExecCommondActionEvent()); closeBtn.addActionListener(new ExecCommondActionEvent()); select_jlb1.addItemListener(select_jlb1Listener); select_jlb2.addItemListener(select_DBType); select_jlb12.addItemListener(select_DBType); select_jlb23.addItemListener(select_jlb23Listener); // radio_jrb1.addActionListener(new Radio_jrb1Listener()); // radio_jrb2.addActionListener(new Radio_jrb1Listener()); jcb2.addItemListener(jcb2Listener); // ********************************************* disabledSrcDataSource(); disabledDescDataSource(); disabledDDLFile(); disabledDMLFile(); disabledDescDDLDML(); disabled(); // ********************************************* } /** 显示菜单 **/ public void showMe() { jframe.setSize(1150, 630); jframe.setLocation(10, 10); jframe.setVisible(true); jframe.setResizable(false); jframe.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); jframe.setAlwaysOnTop(false); } /** * 关闭窗口 */ public void addEventHandler() { jframe.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { exitConfirm(); } }); } private ItemListener select_jlb1Listener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { JComboBox jcb = (JComboBox) e.getSource(); ComboxItem item = (ComboxItem) jcb.getSelectedItem(); disabledSrcDataSource(); disabledDescDataSource(); disabledDDLFile(); disabledDMLFile(); disabledDescDDLDML(); // "请选择", "0:数据源导入", "1:DDL文件导入","2:DML文件导入","3:DDL文件导出","4:DML文件导出" enable(); if (Schema.TYPE_DDL_DML.equals(item.value)) { enabledSrcDataSource(); enabledDescDataSource(); btn4.setEnabled(false); } else if (Schema.TYPE_IMPORT_DDL.equals(item.value)) { enabledDescDataSource(); disabledDescDMLByRadio(); enableOpenDDLFile(); } else if (Schema.TYPE_IMPORT_DML.equals(item.value)) { enabledDescDataSource(); disabledDescDDLByRadio(); enableOpenDMLFile(); } else if (Schema.TYPE_EXPORT_DDL.equals(item.value)) { enabledSrcDataSource(); enableSaveDDLFile(); } else if (Schema.TYPE_EXPORT_DML.equals(item.value)) { enabledSrcDataSource(); enableSaveDMLFile(); } else { disabled(); } } } }; private String getJtfValue13(String dbType) { jtf13.setEditable(true); jtf14.setEditable(true); jtf15.setEditable(true); String default_jtf13 = jtf13.getText(); // "请选择", "0:Oracle", "1:MySql" if (JdbcUtil.DB_TYPE_ORACLE.equals(dbType)) { default_jtf13 = JdbcUtil.DB_TYPE_ORACLE_URL; } else if (JdbcUtil.DB_TYPE_MYSQL.equals(dbType)) { default_jtf13 = JdbcUtil.DB_TYPE_MYSQL_URL; } else if (JdbcUtil.DB_TYPE_INFORMIX.equals(dbType)) { default_jtf13 = JdbcUtil.DB_TYPE_INFORMIX_URL; } else if (JdbcUtil.DB_TYPE_DB2.equals(dbType)) { default_jtf13 = JdbcUtil.DB_TYPE_DB2_URL; } else { jtf13.setEditable(false); jtf14.setEditable(false); jtf15.setEditable(false); } return default_jtf13; } private String getJtfValue3(String dbType) { jtf3.setEditable(true); jtf4.setEditable(true); jtf5.setEditable(true); String default_jtf3 = jtf3.getText(); // "请选择", "0:Oracle", "1:MySql" if (JdbcUtil.DB_TYPE_ORACLE.equals(dbType)) { default_jtf3 = JdbcUtil.DB_TYPE_ORACLE_URL; } else if (JdbcUtil.DB_TYPE_MYSQL.equals(dbType)) { default_jtf3 = JdbcUtil.DB_TYPE_MYSQL_URL; } else if (JdbcUtil.DB_TYPE_INFORMIX.equals(dbType)) { default_jtf3 = JdbcUtil.DB_TYPE_INFORMIX_URL; } else if (JdbcUtil.DB_TYPE_DB2.equals(dbType)) { default_jtf3 = JdbcUtil.DB_TYPE_DB2_URL; } else { jtf3.setEditable(false); jtf4.setEditable(false); jtf5.setEditable(false); } return default_jtf3; } private ItemListener select_DBType = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { JComboBox jcb = (JComboBox) e.getSource(); ComboxItem item = (ComboxItem) jcb.getSelectedItem(); String dbType = item.value; String type = item.type; item = (ComboxItem) select_jlb1.getSelectedItem(); // "请选择", "0:数据源导入", "1:DDL文件导入","2:DML文件导入","3:DDL文件导出","4:DML文件导出" String dbType2 = item.value; String default_jtf13 = jtf13.getText(); String default_jtf3 = jtf3.getText(); if (Schema.TYPE_IMPORT_DDL.equals(dbType2) || Schema.TYPE_IMPORT_DML.equals(dbType2)) { default_jtf13 = getJtfValue13(dbType); } else if (Schema.TYPE_EXPORT_DDL.equals(dbType2) || Schema.TYPE_EXPORT_DML.equals(dbType2)) { default_jtf3 = getJtfValue3(dbType); } else if (Schema.TYPE_DDL_DML.equals(dbType2)) { if (Schema.TYPE_0.equals(type)) { default_jtf3 = getJtfValue3(dbType); } else if (Schema.TYPE_1.equals(type)) { default_jtf13 = getJtfValue13(dbType); } else { } } jtf13.setText(default_jtf13); jtf3.setText(default_jtf3); } } }; private ItemListener select_jlb23Listener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { JComboBox jcb = (JComboBox) e.getSource(); ComboxItem item = (ComboxItem) jcb.getSelectedItem(); absDialect = item.value; log.debug("导出DB文件格式方言:" + absDialect); } } }; // private class Radio_jrb1Listener implements ActionListener { // public void actionPerformed(ActionEvent e) { // JRadioButton rb = (JRadioButton) e.getSource(); // if ("DML".equalsIgnoreCase(rb.getText())) { // disabledDescDDLByRadio(); // } else { // disabledDescDMLByRadio(); // } // } // } private ItemListener jcb2Listener = new ItemListener() { public void itemStateChanged(ItemEvent e) { JCheckBox source = (JCheckBox) e.getSource(); if (source.isEnabled()) { if (source.isSelected()) { enableSqlFileType(); } else { disabledSqlFileType(); } } else { } } }; /** * 设置下拉框值 * * @author zhangjun * */ private void setComboxItems() { Vector<ComboxItem> model = null; // 源数据源 // "请选择", "0:数据源导入", "1:DDL文件导入","2:DML文件导入","3:DDL文件导出","4:DML文件导出" model = new Vector<ComboxItem>(); model.addElement(new ComboxItem("", selectDefaultText)); model.addElement(new ComboxItem(Schema.TYPE_DDL_DML, "数据源导入")); model.addElement(new ComboxItem(Schema.TYPE_IMPORT_DDL, "DDL文件导入")); model.addElement(new ComboxItem(Schema.TYPE_IMPORT_DML, "DML文件导入")); model.addElement(new ComboxItem(Schema.TYPE_EXPORT_DDL, "DDL文件导出")); model.addElement(new ComboxItem(Schema.TYPE_EXPORT_DML, "DML文件导出")); select_jlb1 = new JComboBox(model); model = new Vector<ComboxItem>(); model.addElement(new ComboxItem("", selectDefaultText, Schema.TYPE_0)); model.addElement(new ComboxItem(JdbcUtil.DB_TYPE_ORACLE, JdbcUtil.DB_TYPE_ORACLE, Schema.TYPE_0)); model.addElement(new ComboxItem(JdbcUtil.DB_TYPE_MYSQL, JdbcUtil.DB_TYPE_MYSQL, Schema.TYPE_0)); model.addElement(new ComboxItem(JdbcUtil.DB_TYPE_INFORMIX, JdbcUtil.DB_TYPE_INFORMIX, Schema.TYPE_0)); model.addElement(new ComboxItem(JdbcUtil.DB_TYPE_DB2, JdbcUtil.DB_TYPE_DB2, Schema.TYPE_0)); select_jlb2 = new JComboBox(model); // 目标数据源 // "请选择", "DDL全部", "删除表", "创建表", "创建索引", "创建外键", "删除索引", "删除外键" model = new Vector<ComboxItem>(); model.addElement(new ComboxItem("", selectDefaultText)); model.addElement(new ComboxItem(null, "DDL全部")); model.addElement(new ComboxItem(Schema.DDL_TYPE_CREATE_TABLE, "创建表")); model.addElement(new ComboxItem(Schema.DDL_TYPE_CREATE_FK, "创建外键")); model.addElement(new ComboxItem(Schema.DDL_TYPE_CREATE_IDX, "创建索引")); model.addElement(new ComboxItem(Schema.DDL_TYPE_CREATE_REMARK, "创建备注")); model.addElement(new ComboxItem(Schema.DDL_TYPE_DROP_TABLE, "删除表")); model.addElement(new ComboxItem(Schema.DDL_TYPE_DROP_FK, "删除外键")); model.addElement(new ComboxItem(Schema.DDL_TYPE_DROP_IDX, "删除索引")); select_jlb9 = new JComboBox(model); // "请选择", "插入数据" model = new Vector<ComboxItem>(); model.addElement(new ComboxItem("", selectDefaultText)); model.addElement(new ComboxItem(Schema.DML_TYPE_INSERT_TABLE, "插入数据")); select_jlb10 = new JComboBox(model); model = new Vector<ComboxItem>(); model.addElement(new ComboxItem("", selectDefaultText, Schema.TYPE_1)); model.addElement(new ComboxItem(JdbcUtil.DB_TYPE_ORACLE, JdbcUtil.DB_TYPE_ORACLE, Schema.TYPE_1)); model.addElement(new ComboxItem(JdbcUtil.DB_TYPE_MYSQL, JdbcUtil.DB_TYPE_MYSQL, Schema.TYPE_1)); model.addElement(new ComboxItem(JdbcUtil.DB_TYPE_INFORMIX, JdbcUtil.DB_TYPE_INFORMIX, Schema.TYPE_1)); model.addElement(new ComboxItem(JdbcUtil.DB_TYPE_DB2, JdbcUtil.DB_TYPE_DB2, Schema.TYPE_1)); select_jlb12 = new JComboBox(model); model = new Vector<ComboxItem>(); model.addElement(new ComboxItem("", selectDefaultText)); model.addElement(new ComboxItem(AbsDialect.DB_FILE_TYPE_ORACLE, JdbcUtil.DB_TYPE_ORACLE)); model.addElement(new ComboxItem(AbsDialect.DB_FILE_TYPE_MYSQL, JdbcUtil.DB_TYPE_MYSQL)); model.addElement(new ComboxItem(AbsDialect.DB_FILE_TYPE_INFORMIX, JdbcUtil.DB_TYPE_INFORMIX)); model.addElement(new ComboxItem(AbsDialect.DB_FILE_TYPE_DB2, JdbcUtil.DB_TYPE_DB2)); select_jlb23 = new JComboBox(model); } /*** * 测试DB连接 * * @param str * @return * @throws Exception */ private String testDBConnection(String str) throws Exception { String msg = ""; DBInfo dbInfo = new DBInfo(); try { if (btn1Text.equals(str)) { ComboxItem item = (ComboxItem) select_jlb2.getSelectedItem(); if ("".equals(item.value)) { throw new Exception("请选择源驱动模板"); } dbInfo.setUserName(jtf4.getText()); dbInfo.setPassword(jtf5.getText()); dbInfo.setUrl(jtf3.getText()); dbInfo.setDbType(((ComboxItem) select_jlb2.getSelectedItem()).value); } else if (btn2Text.equals(str)) { ComboxItem item = (ComboxItem) select_jlb12.getSelectedItem(); if ("".equals(item.value)) { throw new Exception("请选择目标驱动模板"); } dbInfo.setUserName(jtf14.getText()); dbInfo.setPassword(jtf15.getText()); dbInfo.setUrl(jtf13.getText()); dbInfo.setDbType(((ComboxItem) select_jlb12.getSelectedItem()).value); } log.debug("数据库类型:" + dbInfo.getDbType()); log.debug("数据库URL:" + dbInfo.getUrl()); log.debug("数据库用户名:" + dbInfo.getUserName()); log.debug("数据库密码:" + dbInfo.getPassword()); if (btn1Text.equals(str)) { conn = (Connection) ServiceConnect.getServiceValue(new JdbcUtil(), "getConnInstance", new Object[] { dbInfo }, 5000); if (conn == null) { msg = "源数据源连接异常"; throw new Exception(msg); } else { msg = "源数据源连接成功"; } } else if (btn2Text.equals(str)) { File logFile = new File("C:" + File.separator + "log" + File.separator); if (!logFile.exists()) { logFile.mkdirs(); } conn = (Connection) ServiceConnect.getServiceValue(new JdbcUtil(), "getConnInstance", new Object[] { dbInfo }, 5000); if (conn == null) { msg = "目标数据源数据源连接异常"; throw new Exception(msg); } else { msg = "目标数据源数据源连接成功"; } } } catch (Exception e1) { msg = "数据库连接失败" + e1.getMessage(); e1.printStackTrace(); throw new Exception(msg); } return msg; } /** * 默认true通过,false不通过 验证数据源 * * @param type * [0:源,1:目标] * @return */ private boolean chkDB(String type) { ComboxItem item = null; if (type == null || Schema.TYPE_0.equals(type)) { item = (ComboxItem) select_jlb2.getSelectedItem(); if ("".equals(item.value)) { JOptionPane.showMessageDialog(null, "请选择源驱动模板", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } if ("".equals(this.jtf3.getText().trim())) { JOptionPane.showMessageDialog(null, "请填写源数据源连接URL串", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } if ("".equals(this.jtf4.getText().trim())) { JOptionPane.showMessageDialog(null, "请填写源数据源用户名", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } if ("".equals(this.jtf5.getText().trim())) { JOptionPane.showMessageDialog(null, "请填写源数据源密码", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } } if (type == null || Schema.TYPE_1.equals(type)) { item = (ComboxItem) select_jlb12.getSelectedItem(); if ("".equals(item.value)) { JOptionPane.showMessageDialog(null, "请选择目标驱动模板", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } if ("".equals(this.jtf13.getText().trim())) { JOptionPane.showMessageDialog(null, "请填写目标数据源连接URL串", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } if ("".equals(this.jtf14.getText().trim())) { JOptionPane.showMessageDialog(null, "请填写目标数据源用户名", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } if ("".equals(this.jtf15.getText().trim())) { JOptionPane.showMessageDialog(null, "请填写目标数据源密码", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } } return true; } /** 验证导入DDL文件 **/ private boolean chkJtf6() { try { String sjtf6 = this.jtf6.getText().trim(); if ("".equals(sjtf6)) { JOptionPane.showMessageDialog(null, "DDL文件不存在,请选择DDL文件", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } File file = new File(sjtf6); if (!file.exists()) { JOptionPane.showMessageDialog(null, "DDL文件不存在,请选择DDL文件", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } } catch (Exception e) { JOptionPane.showMessageDialog(null, "异常信息:" + e.getMessage(), "消息提示", JOptionPane.INFORMATION_MESSAGE); e.printStackTrace(); return false; } return true; } /** 验证导入DML文件 **/ private boolean chkJtf20() { try { String sjtf20 = this.jtf20.getText(); if ("".equals(sjtf20)) { JOptionPane.showMessageDialog(null, "DML文件不存在,请选择DML文件", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } File file = new File(sjtf20); if (!file.exists()) { JOptionPane.showMessageDialog(null, "DML文件不存在,请选择DML文件", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } } catch (Exception e) { JOptionPane.showMessageDialog(null, "异常信息:" + e.getMessage(), "消息提示", JOptionPane.INFORMATION_MESSAGE); e.printStackTrace(); return false; } return true; } /** 验证导出DDL文件 **/ private boolean chkJtf18() { try { String sjtf18 = this.jtf18.getText(); if ("".equals(sjtf18)) { JOptionPane.showMessageDialog(null, "请选择保存的DDL文件路径", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } String dirPath = FileUtil.getFileNameExtension(sjtf18)[0]; File file = new File(dirPath); if (!file.exists()) { file.mkdirs(); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "异常信息:" + e.getMessage(), "消息提示", JOptionPane.INFORMATION_MESSAGE); e.printStackTrace(); return false; } return true; } /** 验证导出DML文件 **/ private boolean chkJtf21() { try { String sjtf21 = this.jtf21.getText(); if ("".equals(sjtf21)) { JOptionPane.showMessageDialog(null, "请选择保存的DML文件路径", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } String dirPath = FileUtil.getFileNameExtension(sjtf21)[0]; File file = new File(dirPath); if (!file.exists()) { file.mkdirs(); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "异常信息:" + e.getMessage(), "消息提示", JOptionPane.INFORMATION_MESSAGE); e.printStackTrace(); return false; } return true; } private boolean chkJlb23() { ComboxItem item = (ComboxItem) select_jlb23.getSelectedItem(); if ("".equals(item.value)) { JOptionPane.showMessageDialog(null, "请选择DB文件格式", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } return true; } /** * 默认true通过,false不通过 * * @return */ private boolean chkDB() { ComboxItem item = null; item = (ComboxItem) select_jlb1.getSelectedItem(); // "请选择", "0:数据源导入", "1:DDL文件导入","2:DML文件导入","3:DDL文件导出","4:DML文件导出" if ("".equals(item.value)) { JOptionPane.showMessageDialog(null, "请选择操作类型", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } if (Schema.TYPE_IMPORT_DDL.equals(item.value)) { if (!chkJtf6()) { return false; } item = (ComboxItem) select_jlb9.getSelectedItem(); if ("".equals(item.value)) { JOptionPane.showMessageDialog(null, "请选择一种DDL操作", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } if (!chkDB(Schema.TYPE_1)) { return false; } } else if (Schema.TYPE_IMPORT_DML.equals(item.value)) { if (!chkJtf20()) { return false; } item = (ComboxItem) select_jlb10.getSelectedItem(); if ("".equals(item.value)) { JOptionPane.showMessageDialog(null, "请选择一种DML操作", "消息提示", JOptionPane.INFORMATION_MESSAGE); return false; } if (!chkDB(Schema.TYPE_1)) { return false; } } else if (Schema.TYPE_EXPORT_DDL.equals(item.value)) { if (!chkJtf18()) { return false; } if (!chkDB(Schema.TYPE_0)) { return false; } } else if (Schema.TYPE_EXPORT_DML.equals(item.value)) { if (!chkJtf21()) { return false; } if (!chkDB(Schema.TYPE_0)) { return false; } } if (!chkJlb23()) { return false; } return true; } private String getTablePatten(String type) { String tablePatten = ""; if (Schema.TYPE_0.equals(type)) { if (otherFrameExport != null) { int[] rows = otherFrameExport.getTable().getSelectedRows(); for (int row : rows) { if (tablePatten != null && !tablePatten.equals("")) { tablePatten += ","; } tablePatten += otherFrameExport.getTable().getValueAt(row, 0); } log.debug("选择的导出表:" + tablePatten); } } else if (Schema.TYPE_1.equals(type)) { if (otherFrameImport != null) { int[] rows = otherFrameImport.getTable().getSelectedRows(); for (int row : rows) { if (tablePatten != null && !tablePatten.equals("")) { tablePatten += ","; } tablePatten += otherFrameImport.getTable().getValueAt(row, 0); } log.debug("选择的导入表:" + tablePatten); } } return tablePatten; } /** * 点击开始执行 * * @author zhangjun * */ private class ExecCommondActionEvent implements ActionListener { public void actionPerformed(ActionEvent e) { String str = e.getActionCommand(); JButton curBtn = (JButton) e.getSource(); log.debug("otherFrameImport====" + otherFrameImport); log.debug("otherFrameExport====" + otherFrameExport); try { curBtn.setEnabled(false); if (execBtnText.equals(str)) { if (!chkDB()) { curBtn.setEnabled(true); return; } ComboxItem item = (ComboxItem) select_jlb1.getSelectedItem(); ComboxItem itemjlb2 = (ComboxItem) select_jlb2.getSelectedItem(); // "请选择", "0:数据源导入", "1:DDL文件导入","2:DML文件导入","3:DDL文件导出","4:DML文件导出" log.debug("选择的操作类型:" + item.text); Schema su = null; boolean jcb1Checked = jcb1.isEnabled() && jcb1.isSelected(); boolean jcb2Checked = jcb2.isEnabled() && jcb2.isSelected(); boolean jcb3Checked = jcb3.isEnabled() && jcb3.isSelected(); if (Schema.TYPE_DDL_DML.equals(item.value)) { String fileName = new Date().getTime() + ".temp"; String fileDir = System.getProperty("user.dir"); if (!fileDir.endsWith(File.separator)) { fileDir += File.separator; } String impExpPath = fileDir + fileName; testDBConnection(btn1.getText()); su = new Schema(conn, absDialect); su.ddlSql = jcb1Checked; su.dmlSql = jcb2Checked; su.dmlSqlMany = jcb3Checked; su.impExpPath = impExpPath; su.type = Schema.TYPE_EXPORT; su.tableNamePattern = getTablePatten(Schema.TYPE_EXPORT); su.absDialect.currentDbType=itemjlb2.value; su.absDialect.registerColumnType(); su.absDialect.setSerializableDBInfo(su); su.exportTableValuesDML(); testDBConnection(btn2.getText()); su = new Schema(conn, absDialect); su.ddlSql = jcb1Checked; su.dmlSql = jcb2Checked; su.dmlSqlMany = jcb3Checked; su.impExpPath = impExpPath; su.type = Schema.TYPE_IMPORT; su.tableNamePattern = getTablePatten(Schema.TYPE_IMPORT); su.absDialect.currentDbType=itemjlb2.value; su.absDialect.registerColumnType(); su.absDialect.setSerializableDBInfo(su); su.importDDL(Schema.DDL_TYPE_DROP_FK); su.importDDL(Schema.DDL_TYPE_DROP_IDX); su.importDDL(Schema.DDL_TYPE_DROP_TABLE); su.importDDL(Schema.DDL_TYPE_CREATE_TABLE); su.importDML(Schema.DML_TYPE_INSERT_TABLE); su.importDDL(Schema.DDL_TYPE_CREATE_FK); su.importDDL(Schema.DDL_TYPE_CREATE_IDX); su.importDDL(Schema.DDL_TYPE_CREATE_REMARK); // 删除临时文件 File file = new File(impExpPath); if (file.exists()) { String filePath = file.getAbsolutePath(); file.delete(); log.debug("删除临时文件【" + filePath + "】成功"); } else { log.debug("删除临时文件失败:临时文件不存在"); } } else if (Schema.TYPE_IMPORT_DDL.equals(item.value)) { testDBConnection(btn2.getText()); su = new Schema(conn, absDialect); su.ddlSql = jcb1Checked; su.dmlSql = jcb2Checked; su.dmlSqlMany = jcb3Checked; su.impExpPath = jtf6.getText(); su.type = Schema.TYPE_IMPORT; su.tableNamePattern = getTablePatten(Schema.TYPE_IMPORT); su.absDialect.currentDbType=itemjlb2.value; su.absDialect.registerColumnType(); su.absDialect.setSerializableDBInfo(su); item = (ComboxItem) select_jlb9.getSelectedItem(); su.importDDL(item.value); } else if (Schema.TYPE_IMPORT_DML.equals(item.value)) { testDBConnection(btn2.getText()); su = new Schema(conn, absDialect); su.ddlSql = jcb1Checked; su.dmlSql = jcb2Checked; su.dmlSqlMany = jcb3Checked; su.impExpPath = jtf20.getText(); su.type = Schema.TYPE_IMPORT; su.tableNamePattern = getTablePatten(Schema.TYPE_IMPORT); su.absDialect.currentDbType=itemjlb2.value; su.absDialect.registerColumnType(); su.absDialect.setSerializableDBInfo(su); item = (ComboxItem) select_jlb10.getSelectedItem(); su.importDML(item.value); } else if (Schema.TYPE_EXPORT_DDL.equals(item.value)) { // 测试导出DDL testDBConnection(btn1.getText()); su = new Schema(conn, absDialect); su.ddlSql = jcb1Checked; su.dmlSql = jcb2Checked; su.dmlSqlMany = jcb3Checked; su.impExpPath = jtf18.getText(); su.type = Schema.TYPE_EXPORT; su.tableNamePattern = getTablePatten(Schema.TYPE_EXPORT); su.absDialect.currentDbType=itemjlb2.value; su.absDialect.registerColumnType(); su.absDialect.setSerializableDBInfo(su); su.exportTableDDLSqls(); } else if (Schema.TYPE_EXPORT_DML.equals(item.value)) { // 测试导出DML testDBConnection(btn1.getText()); su = new Schema(conn, absDialect); su.ddlSql = jcb1Checked; su.dmlSql = jcb2Checked; su.dmlSqlMany = jcb3Checked; su.impExpPath = jtf21.getText(); su.type = Schema.TYPE_EXPORT; su.tableNamePattern = getTablePatten(Schema.TYPE_EXPORT); su.absDialect.currentDbType=itemjlb2.value; su.absDialect.registerColumnType(); su.absDialect.setSerializableDBInfo(su); su.exportTableValuesDML(); } JOptionPane.showMessageDialog(null, "恭喜你!操作成功...", "消息提示", JOptionPane.INFORMATION_MESSAGE); } else if (closeBtnText.equals(str)) { exitConfirm(); } else if (btn1Text.equals(str) || btn2Text.equals(str)) { if (btn1Text.equals(str)) { btn1.setEnabled(false); } else if (btn2Text.equals(str)) { btn2.setEnabled(false); } try { String msg = testDBConnection(str); JOptionPane.showMessageDialog(null, msg, "消息提示", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(null, e1.getMessage(), "消息提示", JOptionPane.INFORMATION_MESSAGE); } if (btn1Text.equals(str)) { btn1.setEnabled(true); } else if (btn2Text.equals(str)) { btn2.setEnabled(true); } } else if ("打开*.DDL".equals(str)) { String rtnPath = openFile(0); if (rtnPath != null && !rtnPath.equals("")) { jtf6.setText(rtnPath); } } else if ("保存*.DDL".equals(str)) { String rtnPath = openFile(1); if (rtnPath != null && !rtnPath.equals("")) { jtf18.setText(rtnPath); } } else if ("打开*.DML".equals(str)) { String rtnPath = openFile(2); if (rtnPath != null && !rtnPath.equals("")) { jtf20.setText(rtnPath); } } else if ("保存*.DML".equals(str)) { String rtnPath = openFile(2); if (rtnPath != null && !rtnPath.equals("")) { jtf21.setText(rtnPath); } } else if (btn3Text.equals(str)) { testDBConnection(btn1.getText()); Schema su = new Schema(conn, absDialect); su.type = Schema.TYPE_SEARCH_DB_TABLES; su.absDialect.setSerializableDBInfo(su); su.absDialect.impExpTableDDLSqls(su); if (su.serializableDBInfo.tableInfoLst == null || su.serializableDBInfo.tableInfoLst.size() == 0) { JOptionPane.showMessageDialog(null, "数据库没有任何表", "消息提示", JOptionPane.INFORMATION_MESSAGE); curBtn.setEnabled(true); } else { otherFrameExport = new DBTableFrame(su.serializableDBInfo.tableInfoLst, curBtn); otherFrameExport.setType(0); otherFrameExport.showMe(); } return; } else if (btn4Text.equals(str)) { ComboxItem item = (ComboxItem) select_jlb1.getSelectedItem(); String importPath = ""; if (Schema.TYPE_IMPORT_DDL.equals(item.value)) { if (!chkJtf6()) { curBtn.setEnabled(true); return; } importPath = jtf6.getText(); } else if (Schema.TYPE_IMPORT_DML.equals(item.value)) { if (!chkJtf20()) { curBtn.setEnabled(true); return; } importPath = jtf20.getText(); } Schema su = new Schema(); su.importPath = importPath; su.deserialization(); if (su.serializableDBInfo.tableInfoLst == null || su.serializableDBInfo.tableInfoLst.size() == 0) { JOptionPane.showMessageDialog(null, "读取文件不存在任何表", "消息提示", JOptionPane.INFORMATION_MESSAGE); curBtn.setEnabled(true); } else { otherFrameImport = new DBTableFrame(su.serializableDBInfo.tableInfoLst, curBtn); otherFrameImport.setType(1); otherFrameImport.showMe(); } return; } } catch (Exception e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(null, "执行失败:" + e1.getMessage(), "错误提示", JOptionPane.ERROR_MESSAGE); } curBtn.setEnabled(true); } } /** 查询表导入 **/ private DBTableFrame otherFrameImport; /** 查询表导出 **/ private DBTableFrame otherFrameExport; public DBTableFrame getOtherFrameImport() { return otherFrameImport; } public void setOtherFrameImport(DBTableFrame otherFrameImport) { this.otherFrameImport = otherFrameImport; } public DBTableFrame getOtherFrameExport() { return otherFrameExport; } public void setOtherFrameExport(DBTableFrame otherFrameExport) { this.otherFrameExport = otherFrameExport; } /** * 退出程序 */ private void exitConfirm() { int op = JOptionPane.showConfirmDialog(jframe, "确定要退出程序吗?", "提示", JOptionPane.YES_NO_OPTION); if (op == JOptionPane.YES_OPTION) { System.exit(0); } } /** * 打开文件 * * @param type * :0[open-DDL],1[save-DDL],2[open-DML],3[save-DML] * @return */ public String openFile(int type) { String rtnPath = ""; JFileChooser chooser = null; Preferences pref = Preferences.userRoot().node(this.getClass().getName()); String lastPath = pref.get("lastPath", ""); if (!lastPath.equals("")) { chooser = new JFileChooser(lastPath); } else { chooser = new JFileChooser(); } chooser.setAcceptAllFileFilterUsed(true); // chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); FileNameExtensionFilter filter1 = null; int returnVal = JFileChooser.ERROR_OPTION; String extension = ""; if (type == 0) { filter1 = new FileNameExtensionFilter("*.ddl", "ddl"); chooser.setFileFilter(filter1); chooser.setDialogTitle("导入DDL"); returnVal = chooser.showOpenDialog(jframe.getFocusOwner()); extension = ".ddl"; } else if (type == 1) { filter1 = new FileNameExtensionFilter("*.ddl", "ddl"); chooser.setFileFilter(filter1); chooser.setDialogTitle("导出DDL"); returnVal = chooser.showSaveDialog(jframe.getFocusOwner()); extension = ".ddl"; } else if (type == 2) { filter1 = new FileNameExtensionFilter("*.dml", "dml"); chooser.setFileFilter(filter1); chooser.setDialogTitle("导入DML"); returnVal = chooser.showOpenDialog(jframe.getFocusOwner()); extension = ".dml"; } else if (type == 3) { filter1 = new FileNameExtensionFilter("*.dml", "dml"); chooser.setFileFilter(filter1); chooser.setDialogTitle("导出DML"); returnVal = chooser.showSaveDialog(jframe.getFocusOwner()); extension = ".dml"; } File chooseFile = null; if (returnVal == JFileChooser.APPROVE_OPTION) { chooseFile = chooser.getSelectedFile(); rtnPath = chooseFile.getPath(); // String des = chooser.getFileFilter().getDescription(); // if (!"temp".equals(getFileExtension(rtnPath))) { // rtnPath += des.replaceFirst("\\*", ""); // } log.debug("You chose this file: " + rtnPath); if (chooseFile != null) { pref.put("lastPath", chooseFile.getPath()); } if (!rtnPath.endsWith(extension)) { rtnPath += extension; } String[] names = FileUtil.getFileNameExtension(rtnPath); if (names != null && names.length > 2) { if ("".equals(names[1])) { rtnPath = (names[0] == null || names[0].equals("") ? "C:" : names[0]) + "zhangjun" + names[2]; } } } return rtnPath; } public JComboBox getSelect_jlb1() { return select_jlb1; } public static SchemaFrameUtil thisFrame = null; /** * 主程序 * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { thisFrame = new SchemaFrameUtil(); thisFrame.setFrame(); thisFrame.showMe(); } }
下载源码后直接部署到eclipse/myeclipse中即可使用
如需要获取源码,请先 登录
本文为张军原创文章,转载无需和我联系,但请注明来自张军的军军小站,个人博客http://www.zhangjunbk.com