當前位置:首頁 » 編程語言 » 將sql語句進行封裝
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

將sql語句進行封裝

發布時間: 2022-10-10 18:21:27

『壹』 sql語句封裝兩個結果集,什麼意思

用以個方法,接受sql語句處理後
賽選出來的數據~~
然後傳給這個方法
方法將數據封裝
在這個方法的集合中

『貳』 SQL將函數封裝到存儲過程,如何實現

思維混亂。沒有邏輯。做事要一件件來。不能這樣稀里糊塗。
第一步:創建函數:

Create function NeterCenter_ChangeChinese
(
@str nvarchar(4000)
)
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--如果非漢字字元,返回原字元
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (
select top 1 PY
from
(
select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC
)
else @word
end)
set @str=right(@str,len(@str)-1)
end
return @PY
end
GO

--第二步:創建存儲過程,調用函數:

create PROCEDURE sp_GetIt
@str varchar(3000)--參數
AS
select dbo.NeterCenter_ChangeChinese(@str) OutStr

--第三步,使用過程
sp_GetIt '我是中國人'

master是系統資料庫,不要將你自己寫的腳步放到該庫,自己創建資料庫。

『叄』 請教如何用C封裝sql語句

假如用戶輸入的姓名和年齡值分別保存在變數name,age中: char sql_insert[200]; sprintf(sql_insert, "INSERT INTO table values('%s','%d');", name, age); mysql_query(&mysql_conn, sql_insert); 上述語句在執行完sprintf語句後,sql_insert...

『肆』 9.6 如何封裝sql 資料庫命令舉例

做成 存儲過程
create procere sp_procere --創建存儲過程
(@key varchar(10)) --設置傳遞的參數(可以沒有)
as
begin
--需封裝的sql語句
end
運行該存儲過程
exec sp_procere 參數

『伍』 如何將SQL的資料庫連接封裝到DLL中

使用C#生成dll文件並調用
一、創建dll文件:

例如生成一個md5編碼判斷狀態的文件,即,輸入一個字元串(string A)和一個32位md5編碼(string B),判斷此字元串A對應的32位md5編碼是否與B相等,如果相等返回true,否則返回false。

打開VS 2005,「文件」--》「新建」--「項目」,選擇「Windows 控制項庫」,命名後點擊「確定」,在「UserControl1.cs」中輸入以下代碼:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

using System.Text;
using System.Security.Cryptography;

namespace md5
{
public partial class Program : UserControl
{
#region MD5 32位加密:GetMd5Str32
/// <summary>
/// 32位MD5加密
/// </summary>
/// <param name="strSource">待加密字串</param>
/// <returns>加密後的字串</returns>
public static string GetMd5Str32(string strSource)
{
byte[] bytes = Encoding.ASCII.GetBytes(strSource);
byte[] hashValue = ((System.Security.Cryptography.HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(bytes);
StringBuilder sb = new StringBuilder();

for (int i = 0; i < 16; i++)
{
sb.Append(hashValue[i].ToString("x2"));
}

return sb.ToString().ToUpper();
}
#endregion

#region 核對md5編碼是否一致:CheckMd5String()

/// <summary>
/// 核對md5編碼是否一致
/// </summary>
/// <param name="ConvertString"></param>
/// <returns>如果一致返回true,否則返回false</returns>
///
public static bool CheckMd5String(string str1, string str2)
{
string md5String = str1; //需要驗證的字元串
string md5DbString = str2; //需要核對的32位md5編碼

int result = string.Compare(md5.Program.GetMd5Str32(str1), md5DbString, true);
if (result == 0)
{
return true;
}
else
{
return false;
}
}
#endregion
}
}

修改「UserControl1.Designer.cs」中的命名空間為「md5」,方法為「Program」,即可生成dll文件。

在...\bin\Debug文件假下,可以找到相應的dll文件。

二、部署dll流程:

首先把dll文件放到應用程序...\bin\Debug\下;
然後在解決方案中添加引用:右鍵滑鼠-->添加引用-->瀏覽-->選擇dll放置路徑後點擊「確定」。
注意:要在應用文件頭處使用using md5;命令。

測試應用程序代碼,如下:Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using md5;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string str1 = textBox1.Text.ToString();
string md5String = textBox2.Text.ToString();

textBox3.Text = md5.Program.GetMd5Str32(str1);
textBox4.Text = md5.Program.CheckMd5String(str1, md5String).ToString();

}

private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

『陸』 在C#中怎麼將所有的sql語句打包成.dll文件或者其他 在C#程序中又怎麼調用呢

我不明白 你是想生成DLL 還是調用?
如果是調用的話! 你只要把你生成好的DLL放到bin目錄下! 然後在你的項目里 using 你的DLL名稱 然後在項目里 實例化一下你的類名就可以了

『柒』 怎麼把sql的資料庫封裝成CDatabaseAccess類

可以參考一下這個:
使用CDatabase類來讀取Microsoft Access資料庫,主要實現了以下功能:
從Microsoft Access 資料庫讀取數據
不使用ODBC數據源進行資料庫連接
在List view控制項中顯示數據
// 以下是部分代碼

void CReadDBDlg::OnRead()
{
// TODO: Add your control notification handler code here

CDatabase database;
CString sSql;
CString sCatID, sCategory;
CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString sDsn;
CString sFile = "c:\\works\\ReadDB\\Test.mdb"; // Change path here
int iRecord = 0;

// Create a pseudo DSN including the name of the Driver and the Excel file
// so we donhave to have an explicit DSN installed in our ODBC admin
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);

TRY
{
// Open the database
database.Open(NULL,false ,false ,sDsn);

// the recordset
CRecordset recset( &database );

// Build the SQL query string
sSql = "SELECT CatID, Category "
"FROM Categories";

// Execute the query)
recset.Open(CRecordset::forwardOnly,sSql,CRecordset::readOnly);
ResetListControl();

// Column heading
m_ListControl.InsertColumn(1,"Cat ID",LVCFMT_LEFT,30,0);
m_ListControl.InsertColumn(1,"Category",LVCFMT_LEFT,30,1);

// Browse the result
while ( !recset.IsEOF() )
{
// Read one record
recset.GetFieldValue("CatID",sCatID);
recset.GetFieldValue("Category",sCategory);

// Insert values into the list control
m_ListControl.InsertItem(0,sCatID,0);
m_ListControl.SetItemText(0,1,sCategory);

// goto next record
recset.MoveNext();
}
// Close the database
database.Close();
}
CATCH(CDBException, e)
{
// If a database exception occured, pop up error msg
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;
}

void CReadDBDlg::ResetListControl()
{
m_ListControl.DeleteAllItems();
int iNbrOfColumns;
CHeaderCtrl* pHeader = (CHeaderCtrl*)m_ListControl.GetDlgItem(0);
if (pHeader)
{
iNbrOfColumns = pHeader->GetItemCount();
}
for (int i = iNbrOfColumns; i >= 0; i--)
{
m_ListControl.DeleteColumn(i);
}
}

『捌』 mybatis是如何將sql執行結果封裝為目標對象並返回的都有哪些映射形式

是寫一個resultmap然後指明欄位和屬性映射關系就行

『玖』 怎麼把sql查詢到的數據用java封裝成對象放到list里

1.新建一個實體類,定義成員變數的分別用於封裝你的數據。2.新建一個List集合用於存儲實體類對象3.new一個對象,用JDBC讀取sql語句,分別給實體類對象的成員變數賦值,再將對象add到集合中,完畢。

『拾』 求高手指教下。我最近在做項目,要求我把SQL封裝成java的介麵包

和資料庫相關的都可以放你的介面里。
另外一些常用的數據操作的方法,也可以一並放進去。