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

📄 datadictionary.java

📁 读取Oracle数据库中的所有表
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

        if(tableElement != null)
            return true;
        return false;
    }
    /**
     *指定名字的XML文档的所有表中,查找一个指定字段名的字段。若找到,返回值为true,否则为false。
     */
    public boolean findTheColumn(String fileName,String columnName) {
        if(columnName == null)
            return false;
        Document doc = new Document();
        SAXBuilder sb = new SAXBuilder();

        try {
            doc = sb.build(new FileInputStream(fileName));
        } catch (IOException ex1) {
            return false;
        } catch (JDOMException ex1) {
        }

        Element root = doc.getRootElement();
        List listOfTable = root.getChildren();
        Iterator itr = listOfTable.iterator();

        while(itr.hasNext()){
            Element tableElement = (Element) itr.next();
            Element columnElement = tableElement.getChild("字段元素" + columnName);
            if(columnElement != null)
                return true;
        }
        return false;
    }
    /**
     *指定名字的XML文档的指定一个表中,查找一个指定字段名的字段。若找到,返回值为true,否则为false。
     */
    public boolean findTheColumn(String fileName,String tableName,String columnName) {
        if(tableName == null)
            return false;
        if(columnName == null)
            return false;
        Document doc = new Document();
        SAXBuilder sb = new SAXBuilder();

        try {
            doc = sb.build(new FileInputStream(fileName));
        } catch (IOException ex1) {
            return false;
        } catch (JDOMException ex1) {
        }

        Element root = doc.getRootElement();
        Element tableElement = root.getChild("表元素" + tableName);
        Element columnElement = null;
        if(tableElement != null)
            columnElement = tableElement.getChild("字段元素" + columnName);
        if(columnElement != null)
            return true;
        return false;
    }
    /**
     *指定名字的XML文档中,查找一个指定注释的表。若找到,返回值为true,否则为false。
     */
    public boolean findTableComment(String fileName,String CommentValue) {
        if(CommentValue == null)
            return false;
        Document doc = new Document();
        SAXBuilder sb = new SAXBuilder();

        try {
            doc = sb.build(new FileInputStream(fileName));
        } catch (IOException ex1) {
            return false;
        } catch (JDOMException ex1) {
        }

        Element root = doc.getRootElement();
        List listOfRoot = root.getChildren();
        Iterator itr = listOfRoot.iterator();

        while(itr.hasNext()) {
            Element tableElement = (Element)itr.next();
            if(CommentValue.compareTo(tableElement.getChild("注释").getText()) == 0)
                return true;
        }
        return false;
    }
    /**
     *指定名字的XML文档的所有表中,查找一个指定注释的字段。若找到,返回值为true,否则为false。
     */
    public boolean findColumnComment(String fileName,String CommentValue) {
        if(CommentValue == null)
            return false;
        Document doc = new Document();
        SAXBuilder sb = new SAXBuilder();

        try {
            doc = sb.build(new FileInputStream(fileName));
        } catch (IOException ex1) {
            return false;
        } catch (JDOMException ex1) {
        }

        Element root = doc.getRootElement();
        List listOfRoot = root.getChildren();
        Iterator itr = listOfRoot.iterator();

        while(itr.hasNext()) {
            Element tableElement = (Element)itr.next();
            List listOfTable = tableElement.getChildren();
            Iterator it = listOfTable.iterator();

            it.next();it.next();it.next();it.next();//跳过前四个无关的结点元素

            while(it.hasNext()) {
                Element columnElement = (Element)it.next();
                if(CommentValue.compareTo(columnElement.getChild("注释").getText()) == 0)
                    return true;
            }
        }
        return false;
    }
    /**
     *指定名字的XML文档的指定一个表中,查找一个指定注释的字段。若找到,返回值为true,否则为false。
     */
    public boolean findColumnComment(String fileName,String tableName,String CommentValue) {
        if(tableName == null)
            return false;
        if(CommentValue == null)
            return false;
        Document doc = new Document();
        SAXBuilder sb = new SAXBuilder();

        try {
            doc = sb.build(new FileInputStream(fileName));
        } catch (IOException ex1) {
            return false;
        } catch (JDOMException ex1) {
        }

        Element root = doc.getRootElement();
        Element tableElement = root.getChild("表元素" + tableName);
        if(tableElement == null)
            return false;
        List listOfTable = tableElement.getChildren();
        Iterator it = listOfTable.iterator();

        it.next();it.next();it.next();it.next();//跳过前四个无关的结点元素
        while(it.hasNext()) {
            Element columnElement = (Element)it.next();
            if(CommentValue.compareTo(columnElement.getChild("注释").getText()) == 0)
                return true;
        }
        return false;
    }
    /**
     *指定名字的XML文档中,查找一个指定名字的表。若找到,返回其注释。
     */
    public String getTableComment(String fileName,String tableName) {
        if(tableName == null)
            return null;
        Document doc = new Document();
        SAXBuilder sb = new SAXBuilder();

        try {
            doc = sb.build(new FileInputStream(fileName));
        } catch (IOException ex1) {
            return null;
        } catch (JDOMException ex1) {
        }

        Element root = doc.getRootElement();
        Element tableElement = root.getChild("表元素" + tableName);

        if(tableElement != null) {
            return tableElement.getChild("注释").getText();
        }
        return null;
    }
    /**
     *指定名字的XML文档的所有表中,查找一个指定字段名的字段。若找到,返回注释。
     */
    public String getColumnComment(String fileName,String columnName) {
        if(columnName == null)
            return null;
        Document doc = new Document();
        SAXBuilder sb = new SAXBuilder();

        try {
            doc = sb.build(new FileInputStream(fileName));
        } catch (IOException ex1) {
            return null;
        } catch (JDOMException ex1) {
        }

        Element root = doc.getRootElement();
        List listOfTable = root.getChildren();
        Iterator itr = listOfTable.iterator();

        while(itr.hasNext()) {
            Element tableElement = (Element) itr.next();
            Element columnElement = tableElement.getChild("字段元素" + columnName);
            if(columnElement != null)
                return columnElement.getChild("注释").getText();
        }
        return null;
    }
    /**
     *指定名字的XML文档的指定一个表中,查找一个指定字段名的字段。若找到,返回注释。
     */
    public String getColumnComment(String fileName,String tableName,String columnName) {
        if(tableName == null)
            return null;
        if(columnName == null)
            return null;
        Document doc = new Document();
        SAXBuilder sb = new SAXBuilder();

        try {
            doc = sb.build(new FileInputStream(fileName));
        } catch (IOException ex1) {
            return null;
        } catch (JDOMException ex1) {
        }

        Element root = doc.getRootElement();
        Element tableElement = root.getChild("表元素" + tableName);
        Element columnElement = null;
        if(tableElement != null)
            columnElement = tableElement.getChild("字段元素" + columnName);
        if(columnElement != null)
            return columnElement.getChild("注释").getText();
        return null;
    }
    /**
     *设置XML文档中的表名注释。
     */
    public void setTableComment(String fileName,String tableName,String CommentValue) {
        if(tableName == null)
            return;
        Document doc = new Document();
        SAXBuilder sb = new SAXBuilder();

        try {
            doc = sb.build(new FileInputStream(fileName));
        } catch (IOException ex1) {
            return;
        } catch (JDOMException ex1) {
        }

        Element root = doc.getRootElement();
        Element tableElement = root.getChild("表元素" + tableName);
        if(tableElement == null)
            return;
        Element comment =tableElement.getChild("注释");
        comment.setText(CommentValue);

        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setEncoding("GB2312"));
        try {
            outputter.output(doc, new FileWriter(fileName));
        } catch (IOException ex) {
        }
    }
    /**
     *设置XML文档中的字段名注释。
     */
    public void setColumnComment(String fileName,String tableName,
                                 String columnName,String CommentValue) {
        if(tableName == null)
            return;
        Document doc = new Document();
        SAXBuilder sb = new SAXBuilder();

        try {
            doc = sb.build(new FileInputStream(fileName));
        } catch (IOException ex1) {
            return;
        } catch (JDOMException ex1) {
        }

        Element root = doc.getRootElement();
        Element tableElement = root.getChild("表元素" + tableName);
        if(tableElement == null)
            return;
        Element columnElement =tableElement.getChild("字段元素" + columnName);
        Element comment = columnElement.getChild("注释");
        comment.setText(CommentValue);

        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setEncoding("GB2312"));
        try {
            outputter.output(doc, new FileWriter(fileName));
        } catch (IOException ex) {
        }
    }
    /**
     *将名字转换为XML文件可以接受的格式。
     */
    public String convertName(String databaseName) {
        String fileName = "";
        boolean isStringEmpty = true;
        int c = 0;
        if(databaseName != null)
            while(c < databaseName.length()) {
                if(databaseName.charAt(c) != ':'
                   &databaseName.charAt(c) != '.'
                   &databaseName.charAt(c) != '@'
                   &databaseName.charAt(c) != '$'
                   &databaseName.charAt(c) != '#') {
                    fileName = fileName + databaseName.charAt(c);
                } else {
                    fileName = fileName + "_";
                }
                c++;
            }
        return fileName;
    }
    ////////////////////////////////////////////////////////////////////////////
    public static void main(String[] args) {
        DataDictionary d = new DataDictionary();

        try {
            d.connectDatabase("oracle.jdbc.driver.OracleDriver",
                              "jdbc:oracle:thin:@127.0.0.1:1521:serbase",
                              "system",
                              "admin");
        } catch (SQLException ex) {
            System.out.println("wrong!");
        }

        //String s = d.getColumnComment("e.xml","ALL_ALL_TABLES","CLUSTER_NAME");
        //System.out.println(s);

        //try {
          //  d.guideXML("e.xml","DICTIONARY","TABLE_NAME","COMMENTS",
         //              "DICT_COLUMNS","COLUMN_NAME","COMMENTS");
       //d.go("e01.xml","DICTIONARY","TABLE_NAME","COMMENTS",
         //             "DICT_COLUMNS","COLUMN_NAME","COMMENTS");
        //} catch (SQLException ex1) {
       //}
        FrameOfDict frame = new FrameOfDict();
    }
}

⌨️ 快捷键说明

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