定义Dictionary


public class ColumnEntity

    {
        public ColumnEntity()
        {
        }
        public string ColumnOwner { get; set; }
        public string ColumnTableName { get; set; }
        public string ColumnName { get; set; }
        public string ColumnType { get; set; }
        public string ColumnLength { get; set; }
        public string ColumnPrecision { get; set; }
        public string ColumnScale { get; set; }
        public string ColumnNULLABLE { get; set; }
        public string ColumnID { get; set; }
        public string ColumnDefault { get; set; }

        public ColumnEntity Clone()
        {
            return this.MemberwiseClone() as ColumnEntity;
        }

    }


public class TableEntity
    {
        public TableEntity()
        {            
        }
        public string TableName { get; set; }


        private Dictionary<string, ColumnEntity> columns = new Dictionary<string, ColumnEntity>();
        public Dictionary<string, ColumnEntity> Columns
        {
            get { return columns; }
            set { this.columns = value; }
        }
    }



public class DataBase
    {
        public DataBase(string connString)
        {
            this.connString = connString;
        }

        private string connString = "";
        private OracleConnection connection;
        public OracleDataReader ExeSql(string sql)
        {
            connection = new OracleConnection(connString);
            OracleCommand command = new OracleCommand(sql);
            command.Connection = connection;
            try
            {
                connection.Open();
                return command.ExecuteReader();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public bool CloseConnection()
        {
            connection.Close();
            return true;
        }
    }




public partial class frmTools : Form
    {
        public frmTools()
        {
            InitializeComponent();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            string connString = string.Format("Data Source={0};user={1};password={2}", "orcl111", "his", "his");
            DataBase db = new DataBase(connString);
            string sql = @"SELECT OWNER,
                                   TABLE_NAME,
                                   COLUMN_NAME,
                                   DATA_TYPE,
                                   DATA_LENGTH,
                                   DATA_PRECISION,
                                   DATA_SCALE,
                                   NULLABLE,
                                   COLUMN_ID,
                                   DATA_DEFAULT
                              FROM ALL_TAB_COLUMNS C
                             WHERE C.OWNER = 'HIS'
                               AND (C.TABLE_NAME = 'ALL' OR 'ALL' = 'ALL')
                               ORDER BY OWNER,TABLE_NAME,COLUMN_ID";
            OracleDataReader reader = db.ExeSql(sql);
            if (reader == null)
            {
                MessageBox.Show("NO data");
                return;
            }
            List<TableEntity> lstTables = new List<TableEntity>();
            TableEntity tableEntity = null;
            string tabName = string.Empty;
            while (reader.Read())
            {
                if (tabName == string.Empty)
                {
                    tableEntity = new TableEntity();
                    tabName = reader["TABLE_NAME"].ToString();
                    tableEntity.TableName = tabName;
                }
                else if (tabName != reader["TABLE_NAME"].ToString())
                {
                    lstTables.Add(tableEntity);
                    tableEntity = new TableEntity();
                    tabName = reader["TABLE_NAME"].ToString();
                    tableEntity.TableName = tabName;
                }

                ColumnEntity colEntity = new ColumnEntity();
                colEntity.ColumnOwner = reader["OWNER"].ToString();
                colEntity.ColumnTableName = reader["TABLE_NAME"].ToString();
                colEntity.ColumnName = reader["COLUMN_NAME"].ToString();
                colEntity.ColumnType = reader["DATA_TYPE"].ToString();
                colEntity.ColumnLength = reader["DATA_LENGTH"].ToString();
                colEntity.ColumnPrecision = reader["DATA_PRECISION"].ToString();
                colEntity.ColumnScale = reader["DATA_SCALE"].ToString();
                colEntity.ColumnNULLABLE = reader["NULLABLE"].ToString();
                colEntity.ColumnID = reader["COLUMN_ID"].ToString();
                colEntity.ColumnDefault = reader["DATA_DEFAULT"].ToString();

                tableEntity.Columns.Add(colEntity.ColumnName, colEntity);
            }
            if (tabName != null)
            {
                lstTables.Add(tableEntity);
            }
            reader.Close();
            db.CloseConnection();
            int spdRowIdx = 0;
            int spdColIdx = 0;
            spdData_View.Rows.Count = 0;
            foreach (TableEntity entity in lstTables)
            {
                foreach (var item in entity.Columns)
                {
                    this.spdData_View.Rows.Count++;
                    spdColIdx = 0;

                    spdData_View.SetValue(spdRowIdx, spdColIdx++, item.Value.ColumnOwner);
                    spdData_View.SetValue(spdRowIdx, spdColIdx++, item.Value.ColumnTableName);
                    spdData_View.SetValue(spdRowIdx, spdColIdx++, item.Value.ColumnName);
                    spdData_View.SetValue(spdRowIdx, spdColIdx++, item.Value.ColumnType);
                    spdData_View.SetValue(spdRowIdx, spdColIdx++, item.Value.ColumnLength);
                    spdData_View.SetValue(spdRowIdx, spdColIdx++, item.Value.ColumnPrecision);
                    spdData_View.SetValue(spdRowIdx, spdColIdx++, item.Value.ColumnScale);
                    spdData_View.SetValue(spdRowIdx, spdColIdx++, item.Value.ColumnNULLABLE);
                    spdData_View.SetValue(spdRowIdx, spdColIdx++, item.Value.ColumnID);
                    spdData_View.SetValue(spdRowIdx++, spdColIdx++, item.Value.ColumnDefault);
                }
            }
        }
    }














好的,这是一个关于Java编程的问题,我可以帮您解答。以下是代码示例: ``` import java.util.*; public class Dictionary { private String eng; private String type; private String chinese; private String example; public String getEng() { return eng; } public void setEng(String eng) { this.eng = eng; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getChinese() { return chinese; } public void setChinese(String chinese) { this.chinese = chinese; } public String getExample() { return example; } public void setExample(String example) { this.example = example; } public static void main(String[] args) { //创建字典词条 Dictionary d1 = new Dictionary(); d1.setEng("hello"); d1.setType("n."); d1.setChinese("你好"); d1.setExample("Hello, how are you?"); Dictionary d2 = new Dictionary(); d2.setEng("world"); d2.setType("n."); d2.setChinese("世界"); d2.setExample("The world is big."); //使用Map存储字典词条 Map<String, Dictionary> map = new HashMap<String, Dictionary>(); map.put(d1.getEng(), d1); map.put(d2.getEng(), d2); //查询并显示词条信息 String word = "hello"; //待查询的单词 Dictionary d = map.get(word); if(d != null) { System.out.println("单词:" + d.getEng()); System.out.println("词性:" + d.getType()); System.out.println("中文释义:" + d.getChinese()); System.out.println("例句:" + d.getExample()); }else { System.out.println("找不到该单词。"); } } } ``` 在上面的代码中,我们首先定义了一个Dictionary类,并在其中添加了eng、type、chinese、example四个属性以及相应的get/set方法。接着,我们创建了两个字典词条,并使用Map存储它们。最后,我们通过查询Map中的元素来显示指定单词的词条信息。 希望这个例子能对您有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值