1、 oracle 存储过程以及 asp.NET 中调用存储过程,实现一个简单的登录功能,只是作为学习的,所以处理可能不太合理。 ① 在 PL/SQLDeveloper 中编写存储过程 新建 Procedures ,一个简单的登录检查存储过程代码如下: createorreplaceprocedureuser_login(s
1、oracle存储过程以及asp.NET中调用存储过程,实现一个简单的登录功能,只是作为学习的,所以处理可能不太合理。
① 在PL/SQL Developer中编写存储过程
新建Procedures,一个简单的登录检查存储过程代码如下:
create or replace procedure user_login(sname in nvarchar2 ,spassword in nvarchar2, ReturnValue out number)
is --变量声明
Rname nvarchar2(20);
Rpassword nvarchar2(50);
begin
ReturnValue :=0; --赋初值
select username into Rname from userinfo where username=sname;
if Rname is not null then
ReturnValue:=1;--用户名存在
select userpassword into Rpassword from userinfo where username=sname and userpassword=spassword;
if Rpassword is not null then
ReturnValue:=2;--登陆成功
else ReturnValue:=1;--用户名存在,密码不正确
return ;
end if;
else ReturnValue:=0;--用户不存在
end if;
exception
when no_data_found then
DBMS_OUTPUT.put_line('没有找到数据');
end;
② 在PL/SQL Developer的SQL窗口中调用存储过程
declare --变量声明
ReturnValue number(10);
begin
user_login('faith','faith',ReturnValue);
if ReturnValue=0 then
DBMS_OUTPUT.put_line('不存在此用户');
elsif ReturnValue=1 then
DBMS_OUTPUT.put_line('存在用户,但密码不正确');
else
DBMS_OUTPUT.put_line('登录成功!!!');
end if;
end;
③ 在VS2012中调用存储过程
在OracleHelper.cs文件中:
public static void iRunProc(string procName, OracleParameter[] paras)
{
OracleConnection conn=new OracleConnection(OracleHelper.strConn);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
OracleCommand cmd = new OracleCommand(procName, conn);
cmd.CommandType = CommandType.StoredProcedure;
if (paras != null)
{
for (int i = 0; i
{
OracleParameter parameter = paras[i];
cmd.Parameters.Add(parameter);
}
}
int result = cmd.ExecuteNonQuery();
cmd.ExecuteNonQuery();
}
DAL层的webtestDal.cs文件中
public static int loginByProc(string name,string password,string procName)
{
OracleParameter[] parameters ={
new OracleParameter("sname", OracleType.NVarChar, 20),
new OracleParameter("spassword", OracleType.NVarChar, 50),
new OracleParameter("ReturnValue", OracleType.Number, 10)
};
parameters[0].Value = name;
parameters[1].Value = password;
//parameters[2].Value = 0;
parameters[0].Direction = ParameterDirection.Input;
parameters[1].Direction = ParameterDirection.Input;
parameters[2].Direction = ParameterDirection.Output;
try
{
OracleHelper.iRunProc(procName, parameters);
int i = int.Parse(parameters[2].Value.ToString());
return i;
}
catch (Exception e)
{
throw e;
}
}
在BLL层的webtestBll.cs文件中
public static int loginByProc(string name, string password, string procName)
{
return webtestDal.loginByProc(name, password, procName);
}
在页面代码的登录按钮事件中
protected void btnSubmit_Click(object sender, EventArgs e)
{
string name = this.txtName.Text.Trim();
string password = this.txtPassword.Text.Trim();
//调用存储过程,判断是否登录成功
if (webtestBll.loginByProc(name, password, "user_login")==2)//存储过程输出2表示登录成功
{//登录成功,保存用户名和密码的cookie
HttpCookie mycookie = new HttpCookie("loginCookie");
mycookie.Values.Add("cname", name);
mycookie.Values.Add("cpassword", password);
mycookie.Expires = DateTime.Now.AddHours(4);//cookie的生命期
Response.AppendCookie(mycookie);
Response.Redirect("userinfo.aspx");
}
else if (webtestBll.loginByProc(name, password, "user_login") == 1)
{
// Response.Write("");
RegisterClientScriptBlock("msg", "<script>alert(\"密码错误!\");</script>");
}
else
RegisterClientScriptBlock("msg", "<script>alert(\"无法认证!\");</script>");
}
2、登录之后,传递cookie值
先获取登录界面的cookie值(代码如上)
将登录页面的cookie值传给跳转页面
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = webtestBll.getAll();
userInfoGrid.DataSource = dt;
if (dt != null)
userInfoGrid.DataBind();
HttpCookie mycookie = null;
if (Request.Cookies.Get("loginCookie") != null)
{//当用户登录了时,获取页面传来的cookie值
mycookie = Request.Cookies.Get("loginCookie");
this.txtLoginName.Text = mycookie.Values["cname"].ToString();
this.txtLoginPassword.Text = mycookie.Values["cpassword"].ToString();
}
else
{//cookie过期或者没登录
Response.Redirect("userLogin.aspx?errorMsg=您还没登陆,请先登陆!");
}
}
}

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

toadduserInmysqleffect和securly,跟隨台詞:1)USEtheCreateUserStattoDaneWuser,指定thehostandastrongpassword.2)GrantNecterAryAryaryPrivilegesSustherthing privilegesgeStatement,usifementStatement,adheringtotheprinciplelastprefilegege.3)

toaddanewuserwithcomplexpermissionsinmysql,loldtheSesteps:1)創建eTheEserWithCreateuser'newuser'newuser'@''localhost'Indedify'pa ssword';。 2)GrantreadAccesstoalltablesin'mydatabase'withGrantSelectOnMyDatabase.to'newuser'@'localhost';。 3)GrantWriteAccessto'

MySQL中的字符串數據類型包括CHAR、VARCHAR、BINARY、VARBINARY、BLOB、TEXT,排序規則(Collations)決定了字符串的比較和排序方式。 1.CHAR適合固定長度字符串,VARCHAR適合可變長度字符串。 2.BINARY和VARBINARY用於二進制數據,BLOB和TEXT用於大對像數據。 3.排序規則如utf8mb4_unicode_ci忽略大小寫,適合用戶名;utf8mb4_bin區分大小寫,適合需要精確比較的字段。

最佳的MySQLVARCHAR列長度選擇應基於數據分析、考慮未來增長、評估性能影響及字符集需求。 1)分析數據以確定典型長度;2)預留未來擴展空間;3)注意大長度對性能的影響;4)考慮字符集對存儲的影響。通過這些步驟,可以優化數據庫的效率和擴展性。

mysqlblobshavelimits:tinyblob(255bytes),blob(65,535 bytes),中間佈洛布(16,777,215個比例),andlongblob(4,294,967,967,295 bytes).tousebl觀察:1)考慮pperformance impactsandSandStorLageBlobSextern; 2)管理backbackupsandreplication carecration; 3)usepathsinst

自動化在MySQL中創建用戶的最佳工具和技術包括:1.MySQLWorkbench,適用於小型到中型環境,易於使用但資源消耗大;2.Ansible,適用於多服務器環境,簡單但學習曲線陡峭;3.自定義Python腳本,靈活但需確保腳本安全性;4.Puppet和Chef,適用於大規模環境,複雜但可擴展。選擇時需考慮規模、學習曲線和集成需求。

是的,YouCansearchInIdeAblobInMysqlusingsPecificteChniques.1)轉換theblobtoautf-8StringWithConvertFunctionWithConvertFunctionandSearchUsiseLike.2)forCompresseBlysBlobs,useuncompresseblobs,useuncompressbeforeconversion.3)expperformance impperformance imptactSandDataEcoding.4)


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SublimeText3 Linux新版
SublimeText3 Linux最新版

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。