国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

我也來學著寫寫WINDOWS服務-解析xml抓取數據并插入數據庫

2019-11-17 02:21:43
字體:
來源:轉載
供稿:網友

我也來學著寫寫WINDOWS服務-解析xml抓取數據并插入數據庫

項目告一段落,快到一年時間開發了兩個系統,一個客戶已經在試用,一個進入客戶測試階段,中間突然被項目經理(更喜歡叫他W工)分派一個每隔兩小時用windows服務去抓取客戶提供的外網xml,解析該xml,然后將截取的節點字段值插入到已經建好相應結構的表中。并記錄日志。

xml結構概要如下:

<?xml version="1.0" encoding="UTF-8"?><list>  <info>    <id>93ef7c7cccd2ecb13ed01dd6e30020b4136</id>    <title>剔骨刀一握六年練過硬本領 女庖丁解牛割肉有拿手好戲</title>    <posttime class="sql-timestamp">2015-05-25 06:38:20.0</posttime>    <institution>浙江省物價局</institution>    <url>http://dsb.66wz.com/html/2015-05/25/content_1822593.htm</url>    <webName>溫州都市報數字版</webName>    <infotype>新聞</infotype>    <summary>內容</summary>    <fl>其他類</fl>  </info>  <info>    ...  </info>  <info>    ...  </info>。。。</list>

1.首先,讓我們新建一個解決方案,該解決方案中包含9個項目:

(1)由于需要操作的是Oracle數據庫系統,所以在MSDN上找了個Oracle數據操作類庫DatabaseLib和DatabaseLink直接拿來用,一個是數據庫連接類,一個是數據庫操作類,里面包含各種對數據庫的操作;

其中,DatabaseLink主要包括以下三個文件:

DbLink.cs

using%20System.Data;namespace%20DataBaseLink{%20%20%20%20///%20<summary>%20%20%20%20///%20DATA%20%20%20%20%20%20:2010-07-01%20%20%20%20///%20Author%20%20%20%20:虞健超(James.Yu)%20%20%20%20///%20Describe%20%20:數據庫連接對象%20%20%20%20///%20</summary>%20%20%20%20public%20class%20DbLink%20:%20IDbLink%20%20%20%20{%20%20%20%20%20%20%20%20public%20string%20ConnectionStr%20{%20get;%20set;%20}%20%20%20%20%20%20%20%20public%20DbLink(string%20connectStr)%20%20%20%20%20%20%20%20{%20%20%20%20%20%20%20%20%20%20%20%20ConnectionStr%20=%20connectStr;%20%20%20%20%20%20%20%20%20}#if%20MSSQL%20%20%20%20%20%20%20%20public%20IDbConnection%20CreateConnection()%20%20%20%20%20%20%20%20{%20%20%20%20%20%20%20%20%20%20%20%20return%20new%20System.Data.SqlClient.SqlConnection(ConnectionStr);%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20public%20IDataAdapter%20CreateAdapter(IDbCommand%20cmd)%20%20%20%20%20%20%20%20{%20%20%20%20%20%20%20%20%20%20%20%20return%20new%20System.Data.SqlClient.SqlDataAdapter((System.Data.SqlClient.SqlCommand)cmd);%20%20%20%20%20%20%20%20}#endif%20%20%20%20}}

IDbLink.cs

using%20System.Data;namespace%20DataBaseLink{%20%20%20%20///%20<summary>%20%20%20%20///%20DATA%20%20%20%20%20%20:2010-07-01%20%20%20%20///%20Author%20%20%20%20:虞健超(James.Yu)%20%20%20%20///%20Describe%20%20:連接創建對象借口%20%20%20%20///%20</summary>%20%20%20%20public%20interface%20IDbLink%20%20%20%20{%20%20%20%20%20%20%20%20///%20<summary>%20%20%20%20%20%20%20%20///%20連接字符串%20%20%20%20%20%20%20%20///%20</summary>%20%20%20%20%20%20%20%20string%20ConnectionStr%20{%20get;%20set;%20}%20%20%20%20%20%20%20%20///%20<summary>%20%20%20%20%20%20%20%20///%20創建連接%20%20%20%20%20%20%20%20///%20</summary>%20%20%20%20%20%20%20%20///%20<returns>連接</returns>%20%20%20%20%20%20%20%20IDbConnection%20CreateConnection();%20%20%20%20%20%20%20%20///%20<summary>%20%20%20%20%20%20%20%20///%20創建Adapter%20%20%20%20%20%20%20%20///%20</summary>%20%20%20%20%20%20%20%20///%20<param%20name="cmd">cmd</param>%20%20%20%20%20%20%20%20///%20<returns></returns>%20%20%20%20%20%20%20%20IDataAdapter%20CreateAdapter(IDbCommand%20cmd);%20%20%20%20}}

以及存儲過程映射類DBStore

public override unsafe int ExecuteNonQuery()        {            string[] ppOpoPrmRefCtx = null;            IntPtr[] pOpoPrmValCtx = null;            OracleParameter parameter;            int num7;            int num8;            IntPtr zero = IntPtr.Zero;            IntPtr opsSubscrCtx = IntPtr.Zero;            int isSubscrRegistered = 0;            OracleDependency dep = null;            int bQueryBasedNTFNRegistration = 0;            int bchgNTFNExcludeRowidInfo = 0;            long num4 = 0L;            int errCode = 0;            int prmCnt = 0;            bool flag = false;            int bFromPool = 0;            CmdTimeoutCtx state = null;            Timer timer = null;            if (OraTrace.m_TraceLevel != 0)            {                OraTrace.Trace(1, new string[] { " (ENTRY) OracleCommand::ExecuteNonQuery()/n" });            }            if (this.m_connection == null)            {                throw new InvalidOperationException();            }            if (this.m_cmdTxtModified && ((this.m_commandText == null) || (this.m_commandText.Length == 0)))            {                throw new InvalidOperationException(OpoErrResManager.GetErrorMesg(ErrRes.ODP_INVALID_VALUE, new string[] { "OracleCommand.CommandText" }));            }            if (this.m_xmlCommandType != OracleXmlCommandType.None)            {                if (OracleXmlCommandType.Query == this.m_xmlCommandType)                {                    this.ExecuteXmlQuery(false);                    return -1;                }                return this.ExecuteXmlSave();            }            this.CheckConStatus();            if (this.m_cmdTxtModified || (this.m_commandType == System.Data.CommandType.StoredProcedure))            {                if (this.m_commandType == System.Data.CommandType.Text)                {                    this.m_selectStmt = isSelectStatement(this.m_commandText);                    this.m_pooledCmdText = this.m_commandText;                }                else if (this.m_commandType == System.Data.CommandType.TableDirect)                {                    this.m_selectStmt = true;                    this.m_pooledCmdText = "Select * from " + this.m_commandText;                }                else if (this.m_commandType == System.Data.CommandType.StoredProcedure)                {                    this.BuildCommandText();                    this.m_selectStmt = false;                    this.m_utf8CmdText = null;                    this.m_addParam = true;                }                UTF8CommandText text = UTF8CommandText.m_pooler.Get(this.m_connection.m_internalConStr, this.m_pooledCmdText) as UTF8CommandText;                if ((text != null) && (text.m_utf8CmdText != IntPtr.Zero))                {                    this.m_utf8CmdText = text;                    this.m_addParam = this.m_utf8CmdText.m_addParam;                    this.m_parsed = this.m_utf8CmdText.m_parsed;                    bFromPool = 1;                }                if (!this.m_parsed && (this.m_commandType == System.Data.CommandType.Text))                {                    this.ParseCommandText();                }                this.m_cmdTxtModified = false;            }            if (this.m_bindByName && (this.m_commandType != System.Data.CommandType.StoredProcedure))            {                flag = true;            }            if (((this.m_NTFNReq != null) && this.m_NTFNAutoEnlist) && (!this.m_connection.m_contextConnection && (OracleNotificationRequest.s_idTable[this.m_NTFNReq.Id] != null)))            {                opsSubscrCtx = OracleNotificationRequest.PopulateChgNTFNSubscrCtx(this, this.m_addRowid, out dep);                if ((dep != null) && dep.m_bIsRegistered)                {                    isSubscrRegistered = 1;                }                if (dep != null)                {                    if (dep.m_OracleRowidInfo == OracleRowidInfo.Exclude)                    {
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海原县| 新河县| 永嘉县| 安仁县| 惠来县| 大同市| 高阳县| 衢州市| 竹北市| 仪征市| 濮阳县| 电白县| 渝中区| 山东| 西宁市| 资源县| 南平市| 措勤县| 顺昌县| 庄浪县| 望谟县| 闽侯县| 沁源县| 景德镇市| 长治市| 阿拉善盟| 耒阳市| 北碚区| 南安市| 泰来县| 淮安市| 长泰县| 且末县| 本溪| 舞钢市| 长春市| 慈利县| 彝良县| 左权县| 留坝县| 富川|