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

          與我一起遨游吧

           

          通過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 閱讀(690) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 秭归县| 温州市| 保亭| 淅川县| 久治县| 木里| 侯马市| 泉州市| 莒南县| 绥化市| 长兴县| 大厂| 柳江县| 怀宁县| 泰顺县| 明星| 蒙山县| 普兰店市| 镇原县| 仙居县| 东城区| 万年县| 阿拉尔市| 渝中区| 松原市| 偃师市| 托克逊县| 成武县| 赣州市| 嵩明县| 水富县| 库伦旗| 牙克石市| 辉县市| 沂南县| 额尔古纳市| 嘉禾县| 南乐县| 泰顺县| 尖扎县| 色达县|