⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frameofdict.java

📁 读取Oracle数据库中的所有表
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                    }
                });
                scrollPanel01.getViewport().setView(table01);

                table01.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                ListSelectionModel rowSM = table01.getSelectionModel();
                rowSM.addListSelectionListener(new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent e) {
                        int row = table01.getSelectedRow();
                        rowBeSelected01 = row;
                        String tableName = table01.getValueAt(row,0).toString();
                        showAttributesInTable02(tableName);
                        repaint();
                    }
                });
                table01.getModel().addTableModelListener(new TableModelListener() {
                    public void tableChanged(TableModelEvent e) {
                        int row = e.getFirstRow();
                        int column = e.getColumn();
                        if(column == 1){
                            TableModel model = (TableModel) e.getSource();
                            String commentValue = model.getValueAt(row, column).
                                                 toString();
                            String tableName = model.getValueAt(row, 0).
                                                 toString();
                            dict.setTableComment(fileName,tableName,commentValue);
                        }
                    }
                });
            }
        });
        menu.add(menuItem);
        //----------------------------
        menuItem = new JMenuItem("导入数据字典",KeyEvent.VK_T);
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                subframe = new JFrame("导入数据字典");
                JPanel subpanel = new JPanel();
                JPanel subpanel01 = new JPanel(new GridLayout(14,1));
                JPanel subpanel02 = new JPanel();
                JButton button01 = new JButton("确定");
                JButton button02 = new JButton("取消");
                subpanel02.add(button01);
                subpanel02.add(button02);
                subpanel.add(subpanel01);
                subpanel.add(subpanel02);
                subframe.add(subpanel);
                JLabel label01 = new JLabel("请输入表的数据字典名");
                JLabel label02 = new JLabel("请输入表名集合的字段名");
                JLabel label03 = new JLabel("请输入表注释集合的字段名");

                JLabel label04 = new JLabel("请输入字段的数据字典名");
                JLabel label05 = new JLabel("请输入字段名集合的字段名");
                JLabel label06 = new JLabel("请输入字段注释集合的字段名");

                JLabel label07 = new JLabel("保存到:");

                textField01 = new JTextField();
                textField02 = new JTextField();
                textField03 = new JTextField();
                textField04 = new JTextField();
                textField05 = new JTextField();
                textField06 = new JTextField();
                textField07 = new JTextField();

                subpanel01.add(label01);
                subpanel01.add(textField01);
                subpanel01.add(label02);
                subpanel01.add(textField02);
                subpanel01.add(label03);
                subpanel01.add(textField03);
                subpanel01.add(label04);
                subpanel01.add(textField04);
                subpanel01.add(label05);
                subpanel01.add(textField05);
                subpanel01.add(label06);
                subpanel01.add(textField06);
                subpanel01.add(label07);
                subpanel01.add(textField07);


                button01.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        subframe.setVisible(false);
                        String fileName = textField07.getText();
                        String dictionary = textField01.getText();
                        String tableNameInDict = textField02.getText();
                        String commentOfTable = textField03.getText();
                        String dictColumn = textField04.getText();
                        String columnNameInDict = textField05.getText();
                        String commentOfColumn = textField06.getText();

                        if(fileName != null&&
                           dictionary != null&&
                           tableNameInDict != null&&
                           commentOfTable !=null&&
                           dictColumn != null&&
                           columnNameInDict != null&&
                           commentOfColumn != null) {
                            try {
                                dict.guideXML(fileName,
                                              dictionary,
                                              tableNameInDict,
                                              commentOfTable,
                                              dictColumn,
                                              columnNameInDict,
                                              commentOfColumn);
                            } catch (SQLException ex) {
                                JFrame tempFrame = new JFrame("错误消息!");
                                JPanel tempPanel = new JPanel();
                                JLabel message = new JLabel("请检查输入及数据库连接");
                                tempPanel.add(message);
                                tempFrame.add(tempPanel);
                                tempFrame.setSize(new Dimension(200,100));
                                tempFrame.setVisible(true);
                            }
                        }else {
                            JFrame tempFrame = new JFrame("错误消息!");
                            JPanel tempPanel = new JPanel();
                            JLabel message = new JLabel("请检查输入及数据库连接");
                            tempPanel.add(message);
                            tempFrame.add(tempPanel);
                            tempFrame.setSize(new Dimension(100,50));
                            tempFrame.setVisible(true);
                        }
                    }
                });
                button02.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        subframe.setVisible(false);
                    }
                });

                subframe.setSize(new Dimension(300,400));
                subframe.setVisible(true);
            }
        });
        menu.add(menuItem);
        //----------------------------
        menuItem = new JMenuItem("连接到数据库",KeyEvent.VK_T);
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFrame subframe = new JFrame();
                JOptionPane optionPane = new JOptionPane();
                        //////////////////======================-0=-0=
                       try {//测试用!
                            dict.connectDatabase(
                                    "oracle.jdbc.driver.OracleDriver",
                                    "jdbc:oracle:thin:@10.60.46.29:1521:serbase",
                                    "system",
                                    "admin");
                        } catch (SQLException ex1) {
                        }
                        fileName = convertName("jdbc:oracle:thin:@10.60.46.29:1521:serbase");
                        if(true){return;}
                        //////////===============-9=90hop8
                        String databaseName = (String)optionPane.showInputDialog(subframe,
                                                                                 "输入所要连接的数据库的名字:",
                                                                                 "连接数据库",
                                                                                 JOptionPane.QUESTION_MESSAGE);
                        boolean isStringEmpty = true;
                        int c = 0;
                        if(databaseName != null)//用以判断输入的数据库名是否为空
                            while(c < databaseName.length()) {
                                if(databaseName.charAt(c) != ' ')
                                    isStringEmpty = false;
                                c++;
                            }
                        if(databaseName == null||isStringEmpty) {//数据库名为空则退出连接数据库的过程
                            JOptionPane.showMessageDialog(subframe, "数据库名不能为空!");
                        } else {
                            String DBDriver = (String)optionPane.showInputDialog(subframe,
                                                                                 "输入数据库驱动名:",
                                                                                 "连接数据库",
                                                                                 JOptionPane.QUESTION_MESSAGE);
                            isStringEmpty = true;
                            c = 0;
                            if(DBDriver != null)//用以判断输入的驱动名是否为空
                                while(c < DBDriver.length()) {
                                    if(DBDriver.charAt(c) != ' ')
                                        isStringEmpty = false;
                                    c++;
                                }
                            if(DBDriver == null||isStringEmpty) {//数据库驱动名为空则退出连接数据库的过程
                                JOptionPane.showMessageDialog(subframe, "数据库驱动名不能为空!");
                            } else {
                                String userName = (String)optionPane.showInputDialog(subframe,
                                                                                     "输入用户的名字:",
                                                                                     "连接数据库",
                                                                                     JOptionPane.QUESTION_MESSAGE);
                                String password = (String)optionPane.showInputDialog(subframe,
                                                                                     "输入密码:",
                                                                                     "连接数据库",
                                                                                     JOptionPane.QUESTION_MESSAGE);
                                try {
                                    dict.connectDatabase(DBDriver, databaseName, userName,password);
                                    fileName = convertName(databaseName);
                                } catch (SQLException ex) {
                                    JOptionPane.showMessageDialog(subframe, "无法连接到数据库!");
                                }
                            }
                        }
                    }
                });
        menu.add(menuItem);
        //----------------------------
        menuItem = new JMenuItem("为当前数据库创建新的XML文档",KeyEvent.VK_T);
        menuItem.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        JFrame subframe = new JFrame();
                        if(!dict.isConnected()) {
                            JOptionPane.showMessageDialog(subframe, "请先连接到数据库!");
                            return;
                        }
                        try {
                            FileInputStream fileInput = new FileInputStream(fileName);
                        } catch (FileNotFoundException ex) {
                            try {
                                dict.createXML(fileName);
                            } catch (SQLException ex1) {
                            }
                            return;
                        }
                        Object[] possibilities = {"YES","NO"};
                        String doCover = (String)JOptionPane.showInputDialog(subframe,
                                                                          "警告:该文档已经存在! \n"+
                                                                          "     你确定要覆盖它吗?",
                                                                          "创建新的XML文档",
                                                                          JOptionPane.QUESTION_MESSAGE,
                                                                          null,
                                                                          possibilities,
                                                                          "NO");
                        if(doCover == null) return;
                        if(doCover.compareTo("YES") == 0) {
                            try {
                                dict.createXML(fileName);
                            } catch (SQLException ex1) {
                            }
                        }
                    }
                });
        menu.add(menuItem);
        //----------------------------
        menu.addSeparator();
        //----------------------------
        menuItem = new JMenuItem("退出文档及当前数据库连接",KeyEvent.VK_T);
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                fileName = " ";
                dict.closeConnect();
            }
        });

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -