用原廠模式開發多資料庫連接類__資料庫

來源:互聯網
上載者:User

        用原廠模式開發多資料庫連接類,是原廠模式最好的應用方式,也是很多初級使用設計模式的程式員都會涉及到的,下面是具體代碼:
A、建立一個類庫,裡面有如下這些類
一、設計一個抽象類別 using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.Data;
using  System.Configuration;

// 原廠模式串連資料庫
namespace  DBAccess
... {
    //資料連線的原廠模式抽象類別
    public abstract class DBabstract
    ...{
        //建構函式
        public DBabstract()
        ...{ 
        }

        //開啟一個串連
        public abstract void Open();

        //關閉一個串連
        public abstract void Close();

        //資料讀取的公用數
        public abstract void PublicClass(string procname, object[] parmas);

        //執行無返回DataSet的函數
        public abstract string Execsql(string procname, object[] parmas);

        //執行有返回DataSet的函數
        public abstract DataSet ExecSqlReturnDataSet(string tablename, string procname, object[] parmas);

    }
}

二、定義一個Oracle串連類 using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.Data;
using  System.Data.OracleClient;
using  System.Configuration;

// 原廠模式串連資料庫中的ORACLE資料庫連接
namespace  DBAccess
... {
    //資料連線的原廠模式ORACLE串連類
    internal class DBOracle : DBabstract
    ...{
        private OracleConnection conn = null;  //資料連線
        private OracleCommand cmd = null;      //串連命令

        //建構函式
        public DBOracle(string constring)
        ...{
            this.conn = new OracleConnection(constring);
        }

        //開啟一個串連
        public override void Open()
        ...{
            if (this.conn != null && this

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.