我的空間,寫我所寫,禪我所藏

          與我一起遨游吧

           

          通過comment查找中文名的數據庫表

          package com.augurit.pysz.common.excelUtil;

          import java.sql.Connection;
          import java.sql.DriverManager;
          import java.sql.PreparedStatement;
          import java.sql.ResultSet;
          import java.sql.SQLException;
          import java.util.ArrayList;
          import java.util.Iterator;
          import java.util.List;

          import com.augur.wf.shark.common.Db.DbConnectionManager;
          import com.augurit.pysz.common.excelUtil.model.TableValue;

          /**
           * 從hibernate中將table的表結構找出來。 imcb 2007.6.26
           */
          public class RetrieveTableContext {

           public Connection testDB() throws ClassNotFoundException, SQLException {
            Connection con = null;
            Class.forName("oracle.jdbc.driver.OracleDriver");
            con = DriverManager.getConnection(
              "jdbc:oracle:thin:@192.168.13.65:1521:pysz", "shark", "shark");
            return con;
           }

           /**
            * 通過表名查找表的英文名
            * 
            * @param dbName數據庫實例名稱
            * @return
            */
           public List getAllTableName(String dbName) {
            List ls = new ArrayList();
            Connection con = null;  
            try {
             // con = DbConnectionManager.getInstance().getConnection("idb");
             con = this.testDB();   
             String sql = "select * from sys.all_tab_comments t where t.table_type = 'TABLE' and t.owner = '"+dbName+"'";
             PreparedStatement psts = con.prepareStatement(sql);
             ResultSet rs = psts.executeQuery();
             int i=0;
             while(rs.next()){
              TableValue tv = new TableValue();
              System.out.println(++i+"條 :");
              System.out.print(rs.getString(1)+" : ");
              tv.setDbName(rs.getString(1));
              System.out.print(rs.getString(2)+" : ");
              tv.setTableName(rs.getString(2));
              System.out.print(rs.getString(3)+" : ");
              tv.setDbType(rs.getString(3));
              System.out.println(rs.getString(4));
              tv.setComment(rs.getString(4));
              ls.add(tv);
             }
            } catch (Exception we) {
             
            } finally {
             DbConnectionManager.getInstance().freeConnection("idb", con);
            } 

            return ls;
           }
           /**
            * 通過表名查找表的英文名
            *
            * @param str1
            * @param dbName數據庫實例名稱
            * @return
            */ 
           public String getTableName(String str1,String dbName){  
            String tableName = new String();
            List ls = this.getAllTableName(dbName);
            Iterator iterator =ls.iterator();
            while(iterator.hasNext()){
             TableValue tv =(TableValue)iterator.next();
             boolean hasStr = tv.getComment().contains(str1);
             if(hasStr)return tv.getTableName();
            }
            return tableName;
           }
           /**
            * 通過表名查找數據表屬性值。
            *
            * @param tableName
            *            表的英文名
            * @return
            */
           public List getTableContext(String tableName) {
            List tList = new ArrayList();

            return tList;
           }
           
           public static void main(String[] str1){
          //  RetrieveTableContext rtc = new RetrieveTableContext();
          //  rtc.getTableName("d","SHARK");
            String u="string yu";
            String in = "s";
            String out = "e";  
            System.out.println(in.contains(in));//in是否包含in字符串
            System.out.println(u.contains(out));  
           }
          }

          posted on 2007-06-27 10:22 imcb 閱讀(694) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 荆州市| 聂荣县| 绩溪县| 隆德县| 蓬溪县| 丰台区| 蓬莱市| 临沭县| 西昌市| 芒康县| 阜平县| 五台县| 潜山县| 平湖市| 凌海市| 绍兴市| 和平区| 定结县| 鲁甸县| 内乡县| 南汇区| 区。| 南宁市| 龙江县| 固安县| 安宁市| 吉安市| 镇康县| 余姚市| 阳春市| 读书| 姜堰市| 汝南县| 德阳市| 柯坪县| 苏尼特左旗| 稻城县| 丁青县| 香格里拉县| 上林县| 通城县|