Java Web 開發(fā)從入門到實(shí)踐課件 第8章 - JDBC編程_第1頁(yè)
Java Web 開發(fā)從入門到實(shí)踐課件 第8章 - JDBC編程_第2頁(yè)
Java Web 開發(fā)從入門到實(shí)踐課件 第8章 - JDBC編程_第3頁(yè)
Java Web 開發(fā)從入門到實(shí)踐課件 第8章 - JDBC編程_第4頁(yè)
Java Web 開發(fā)從入門到實(shí)踐課件 第8章 - JDBC編程_第5頁(yè)
已閱讀5頁(yè),還剩43頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第三篇

JavaWeb提高篇JavaWeb開發(fā)從入門到實(shí)踐JavaWebDevelopmentFromIntroductiontoPracticeJDBC編程Chap08提綱JDBC編程介紹了如何通過(guò)JDBC連接和操作MySQL數(shù)據(jù)庫(kù),并深入探討了JDBC高級(jí)編程技術(shù),如批量處理、事務(wù)管理和連接池的應(yīng)用。8.1使用JDBC訪問(wèn)MySQL數(shù)據(jù)庫(kù)8.2JDBC高級(jí)編程8.3本章小結(jié)8.1使用JDBC訪問(wèn)MySQL數(shù)據(jù)庫(kù)8.1.1JDBC概述8.1.2連接MySQL數(shù)據(jù)庫(kù)8.1.3基于Statement實(shí)現(xiàn)CRUD操作8.1.4基于PreparedStatement優(yōu)化代碼8.1.1JDBC概述JDBC(JavaDataBaseConnectivity,Java數(shù)據(jù)庫(kù)連接)是Java訪問(wèn)數(shù)據(jù)庫(kù)的標(biāo)準(zhǔn)規(guī)范,由一系列連接數(shù)據(jù)庫(kù)、執(zhí)行SQL語(yǔ)句和操作結(jié)果集的類和接口構(gòu)成。圖

8-1

應(yīng)用程序使用JDBC訪問(wèn)數(shù)據(jù)庫(kù)的方式8.1.1JDBC概述表

8-1

JDBC常用接口、類及其描述接口描述DriverDriver是一種數(shù)據(jù)庫(kù)驅(qū)動(dòng),充當(dāng)Java程序與各種不同類型的數(shù)據(jù)庫(kù)之間的連接器DriverManager用于數(shù)據(jù)庫(kù)驅(qū)動(dòng)程序管理的類,作用于用戶和驅(qū)動(dòng)程序之間Connection數(shù)據(jù)庫(kù)連接對(duì)象,一個(gè)Connection對(duì)象表示通過(guò)JDBC驅(qū)動(dòng)與數(shù)據(jù)源建立的連接Statement向數(shù)據(jù)庫(kù)發(fā)送SQL語(yǔ)句的對(duì)象,執(zhí)行對(duì)數(shù)據(jù)庫(kù)的數(shù)據(jù)的檢索、增加、更新、刪除操作PreparedStatement繼承了Statement接口,執(zhí)行預(yù)編譯的SQL語(yǔ)句,執(zhí)行效率更高ResultSet用來(lái)暫時(shí)存放數(shù)據(jù)庫(kù)查詢操作獲得的結(jié)果8.1.2連接MySQL數(shù)據(jù)庫(kù)在創(chuàng)建MySQL數(shù)據(jù)庫(kù)連接對(duì)象之前,需要先使用JVM注冊(cè)JDBC驅(qū)動(dòng)程序,注冊(cè)數(shù)據(jù)庫(kù)驅(qū)動(dòng)有以下兩種方式。直接調(diào)用DriverManager注冊(cè)DriverManager.registerDriver(newcom.mysql.cj.jdbc.Driver());使用java.lang.Class的靜態(tài)方法forName()注冊(cè)MySQL驅(qū)動(dòng)(常用)Class.forName("com.mysql.cj.jdbc.Driver");//注冊(cè)MySQL驅(qū)動(dòng)8.1.2連接MySQL數(shù)據(jù)庫(kù)使用java.sql.DriverManager類的靜態(tài)方法getConnection()創(chuàng)建Connection接口對(duì)象,一般使用帶三個(gè)參數(shù)的getConnection()方法,參數(shù)一表示數(shù)據(jù)庫(kù)連接URL,參數(shù)1的格式如下:jdbc:數(shù)據(jù)庫(kù)廠商名://ip地址:端口號(hào)/數(shù)據(jù)庫(kù)名jdbc:mysql://localhost:3306/jdbc_dbgetConnection()方法參數(shù)2是數(shù)據(jù)庫(kù)軟件的賬號(hào),參數(shù)3是數(shù)據(jù)庫(kù)軟件的密碼。獲取數(shù)據(jù)庫(kù)連接對(duì)象ConnectionStringurl="jdbc:mysql://localhost:3306/jdbc_dbStringusername="root";//用戶名

Stringpassword="123456";//密碼

Connectionconnection=DriverManager.getConnection(url,username,password);8.1.3基于Statement實(shí)現(xiàn)CRUD操作數(shù)據(jù)庫(kù)的操作常被稱為CRUD,CRUD是計(jì)算機(jī)編程中常用的四個(gè)基本操作的首字母縮寫,它代表了Create(創(chuàng)建)、Retrieve(檢索)、Update(更新)和Delete(刪除)這四種操作。準(zhǔn)備環(huán)境和數(shù)據(jù)庫(kù)表CREATEDATABASEIFNOTEXISTSjdbc_db;USEjdbc_db;DROPTABLEIFEXISTSusers;CREATETABLEusers(

useridint(11)NOTNULLAUTO_INCREMENT,

usernamevarchar(50)NOTNULL,

pwdvarchar(50)NOTNULL,

emailvarchar(50),

PRIMARYKEY(userid))insertintousers(username,pwd,email)values('charles','123456','charles@');insertintousers(username,pwd,email)values('mia','123456','mia@');insertintousers(username,pwd,email)values('jack','123456',jack@');8.1.3基于Statement實(shí)現(xiàn)CRUD操作Statement對(duì)象@WebServlet("/UsersServlet")publicclassUsersServletextendsHttpServlet{ @Override protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{ resp.setContentType("text/html;charset=utf-8"); PrintWriterout=resp.getWriter(); Connectionconn=null; Statementstmt=null; ResultSetrs=null; try{ Class.forName("com.mysql.cj.jdbc.Driver");//注冊(cè)MySQL驅(qū)動(dòng) Stringurl="jdbc:mysql://localhost:3306/jdbc_db?serverTimezone=GMT&characterEncoding=UTF-8";8.1.3基于Statement實(shí)現(xiàn)CRUD操作 Stringusername="root";//用戶名 Stringpassword="123456";//密碼 conn=DriverManager.getConnection(url,username,password);//獲取數(shù)據(jù)庫(kù)連接 stmt=conn.createStatement();//獲取Statement Stringsql="selectuserid,username,pwd,emailfromusers"; rs=stmt.executeQuery(sql);//執(zhí)行查詢,返回結(jié)果集 out.println("<!DOCTYPEhtml>"); out.println("<HTML>"); out.println("<HEAD><TITLE>用戶信息列表</TITLE></HEAD>");

8.1.3基于Statement實(shí)現(xiàn)CRUD操作 out.println("<BODY>"); out.println("<center><h3>用戶信息列表</h3>"); out.println("<tableborder=\"1\"width=\"500px\"cellspacing=\"1\">"); out.println("<tr>"); out.println("<td>用戶編號(hào)</td><td>用戶名</td><td>用戶密碼</td><td>Email</td>"); out.println("</tr>"); while(rs.next()){//循環(huán)結(jié)果集 intuserid=rs.getInt("userid");//獲取ID Stringname=rs.getString("username");//獲取用戶名 Stringpwd=rs.getString("pwd");//獲取密碼 Stringemail=rs.getString("email");//獲取Email

out.println("<tr>"); out.println("<td>"+userid+"</td><td>"+name+"</td><td>"+pwd+"</td><td>"+email+"</td>"); out.println("</tr>"); } out.println("</table>"); out.println("</center>");

8.1.3基于Statement實(shí)現(xiàn)CRUD操作 out.println("</BODY>"); out.println("</HTML>"); out.flush(); out.close(); }catch(Exceptione){ thrownewRuntimeException(e); }finally{ //關(guān)閉資源 try{ if(rs!=null)rs.close(); if(stmt!=null)stmt.close(); if(conn!=null)conn.close(); }catch(SQLExceptione){ e.printStackTrace(); } }}}8.1.3基于Statement實(shí)現(xiàn)CRUD操作圖

8-2

用戶信息列表8.1.3基于Statement實(shí)現(xiàn)CRUD操作案例:使用Statement實(shí)現(xiàn)用戶的增加功能創(chuàng)建一個(gè)html頁(yè)面addUser.html<formmethod="post"action="UserAddServlet">

用戶名:<inputtype="text"name="username"/><br/>

用戶密碼:<inputtype="password"name="password"/><br/>

Email:<inputtype="text"name="email"/><br/>

<inputtype="submit"value="保存"/><inputtype="reset"value="重置">

</form>8.1.3基于Statement實(shí)現(xiàn)CRUD操作UserAddServlet.java@WebServlet("/UserAddServlet")publicclassUserAddServletextendsHttpServlet{ @Override protectedvoiddoPost(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{//獲取表單元素 Stringname=req.getParameter("username"); Stringpwd=req.getParameter("password"); Stringemail=req.getParameter("email"); Connectionconn=null; Statementstmt=null; introws=0;

8.1.3基于Statement實(shí)現(xiàn)CRUD操作 try{ Class.forName("com.mysql.cj.jdbc.Driver");//注冊(cè)MySQL驅(qū)動(dòng) Stringurl="jdbc:mysql://localhost:3306/jdbc_db?serverTimezone=GMT&characterEncoding=UTF-8"; Stringusername="root";//用戶名 Stringpassword="123456";//密碼 conn=DriverManager.getConnection(url,username,password);//獲取數(shù)據(jù)庫(kù)連接 stmt=conn.createStatement();//獲取Statement Stringsql="insertintousers(username,pwd,email)values('"+name+"','"+pwd+"','"+email+"')"; rows=stmt.executeUpdate(sql);//執(zhí)行插入 }catch(Exceptione){ thrownewRuntimeException(e); }8.1.3基于Statement實(shí)現(xiàn)CRUD操作finally{ //關(guān)閉資源 try{ if(stmt!=null)stmt.close(); if(conn!=null)conn.close(); }catch(SQLExceptione){ e.printStackTrace(); } } if(rows>0){ System.out.println("添加成功"); }else{ System.out.println("添加失敗"); } }}8.1.3基于Statement實(shí)現(xiàn)CRUD操作...rows=stmt.executeUpdate(sql,Statement.RETURN_GENERATED_KEYS);//執(zhí)行插入 if(rows>0){

//獲取回顯的主鍵 ResultSetgeneratedKeys=stmt.getGeneratedKeys(); generatedKeys.next(); intid=generatedKeys.getInt(1); System.out.println("添加成功,主鍵為:"+id); }else{ System.out.println("添加失敗"); }...如果實(shí)現(xiàn)自增長(zhǎng)主鍵回顯,只需在上述代碼基礎(chǔ)上進(jìn)行修改,不同部分已用粗體紅色字體標(biāo)出8.1.4基于PreparedStatement優(yōu)化代碼PreparedStatement是預(yù)先對(duì)SQL語(yǔ)句的框架進(jìn)行編譯,然后再給SQL語(yǔ)句傳“值”,傳入的值只會(huì)代替SQL語(yǔ)句中的占位符“?”,PreparedStatement可以解決SQL注入的問(wèn)題。@WebServlet("/LoginServlet")

publicclassLoginServletextendsHttpServlet{

@Override

protectedvoiddoPost(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{

Stringname=req.getParameter("username");

Stringpwd=req.getParameter("password");

Connectionconn=null;

PreparedStatementstmt=null;

ResultSetrs=null;

intcount=0;

try{

Class.forName("com.mysql.cj.jdbc.Driver");//注冊(cè)MySQL驅(qū)動(dòng)

Stringurl="jdbc:mysql://localhost:3306/jdbc_db?serverTimezone=GMT&characterEncoding=UTF-8";Stringusername="root";//用戶名

Stringpassword="123456";//密碼

conn=DriverManager.getConnection(url,username,password);//獲取數(shù)據(jù)庫(kù)連接

8.1.4基于PreparedStatement優(yōu)化代碼Stringsql="selectcount(*)fromuserswhereusername=?andpwd=?";

stmt=conn.prepareStatement(sql);//獲取PreparedStatement

stmt.setString(1,name);//給占位符賦值

stmt.setString(2,pwd);

rs=stmt.executeQuery();

if(rs.next()){

count=rs.getInt(1);

}

}catch(Exceptione){

thrownewRuntimeException(e);

}finally{

//關(guān)閉資源

try{

if(rs!=null)rs.close();

if(stmt!=null)stmt.close();

if(conn!=null)conn.close();

}catch(SQLExceptione){

e.printStackTrace();

}

}

8.1.4基于PreparedStatement優(yōu)化代碼if(count>0){

System.out.println("登錄成功");

}else{

System.out.println("登錄失敗");

}

}

}8.2JDBC高級(jí)編程8.2.1JDBC中數(shù)據(jù)庫(kù)事務(wù)實(shí)現(xiàn)8.2.2批量插入提升性能8.2.3使用CallableStatement訪問(wèn)存儲(chǔ)過(guò)程8.2.4使用連接池優(yōu)化數(shù)據(jù)庫(kù)訪問(wèn)效率8.2.1JDBC中數(shù)據(jù)庫(kù)事務(wù)實(shí)現(xiàn)在JDBC中通過(guò)Connection對(duì)象的setAutoCommit(false)方法關(guān)閉自動(dòng)提交事務(wù),通過(guò)Connection對(duì)象的commit()方法手動(dòng)提交事務(wù)。案例:銀行轉(zhuǎn)賬創(chuàng)建表bankDROPTABLEIFEXISTSbank;CREATETABLEbank( idINTPRIMARYKEYAUTO_INCREMENT, accountVARCHAR(50)NOTNULLUNIQUE, moneyDECIMAL(10,2)UNSIGNED);INSERTINTObank(account,money)values('1001',10000);INSERTINTObank(account,money)values('1002',5000);8.2.1JDBC中數(shù)據(jù)庫(kù)事務(wù)實(shí)現(xiàn)創(chuàng)建類BankDaopublicclassBankDao{publicvoidtransfer(Stringaccount,BigDecimalmoney,Stringtype,Connectionconn){ PreparedStatementstmt=null; introws=0; try{ Stringsql=""; if(type.equals("存款")){ sql="updatebanksetmoney=money+?whereaccount=?"; }else{ sql="updatebanksetmoney=money-?whereaccount=?"; } stmt=conn.prepareStatement(sql);//創(chuàng)建PreparedStatement stmt.setObject(1,money); stmt.setString(2,account); stmt.executeUpdate(); }catch(Exceptione){ thrownewRuntimeException(e); }8.2.1JDBC中數(shù)據(jù)庫(kù)事務(wù)實(shí)現(xiàn)創(chuàng)建類BankDaofinally{ //關(guān)閉資源 try{ if(stmt!=null)stmt.close(); }catch(SQLExceptione){ e.printStackTrace(); } }}}8.2.1JDBC中數(shù)據(jù)庫(kù)事務(wù)實(shí)現(xiàn)創(chuàng)建類BankServicepublicclassBankService{BankDaobankDao=newBankDao();publicvoidtransfer(StringaccountFrom,StringaccountTo,BigDecimalmoney){ Connectionconn=null; try{ Class.forName("com.mysql.cj.jdbc.Driver");//注冊(cè)MySQL驅(qū)動(dòng) Stringurl="jdbc:mysql://localhost:3306/jdbc_db?serverTimezone=GMT&characterEncoding=UTF-8"; Stringusername="root";//用戶名 Stringpassword="123456";//密碼 conn=DriverManager.getConnection(url,username,password);//獲取數(shù)據(jù)庫(kù)連接 conn.setAutoCommit(false); bankDao.transfer(accountFrom,money,"取款",conn); bankDao.transfer(accountTo,money,"存款",conn); mit(); }8.2.1JDBC中數(shù)據(jù)庫(kù)事務(wù)實(shí)現(xiàn)catch(Exceptione){ e.printStackTrace();}finally{ try{ if(conn!=null)conn.close(); }catch(SQLExceptione){ thrownewRuntimeException(e); }}}}8.2.1JDBC中數(shù)據(jù)庫(kù)事務(wù)實(shí)現(xiàn)@WebServlet("/BankServlet")publicclassBankServletextendsHttpServlet{ @Override protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{ BankServicebankService=newBankService(); bankService.transfer("1001","1002",BigDecimal.valueOf(20000f)); }}BankServlet8.2.2批量插入提升性能普通單條插入@WebServlet("/NormalInsertServlet")

publicclassNormalInsertServletextendsHttpServlet{

@Override

protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{Connectionconn=null;

Statementstmt=null;

introws=0;

longstart=System.currentTimeMillis();

try{

Class.forName("com.mysql.cj.jdbc.Driver");//注冊(cè)MySQL驅(qū)動(dòng)

Stringurl="jdbc:mysql://localhost:3306/jdbc_db?serverTimezone=GMT&characterEncoding=UTF-8";

Stringusername="root";//用戶名

Stringpassword="123456";//密碼

conn=DriverManager.getConnection(url,username,password);//獲取數(shù)據(jù)庫(kù)連接stmt=conn.createStatement();//獲取Statement

8.2.2批量插入提升性能普通單條插入 for(inti=0;i<10000;i++){

Stringsql="insertintousers(username,pwd,email)

"+"values('username"+i+"','password"+i+"','email"+i+"')";

stmt.executeUpdate(sql);

}

}catch(Exceptione){

thrownewRuntimeException(e);

}finally{

//關(guān)閉資源

try{

stmt.close();

conn.close();

}catch(SQLExceptione){

e.printStackTrace();

}

}

longend=System.currentTimeMillis();

System.out.println("用時(shí):"+(end-start)+"毫秒");

}

}8.2.2批量插入提升性能圖

8-3

普通插入的用時(shí)圖

8-4

批量插入的用時(shí)8.2.2批量插入提升性能批量插入@WebServlet("/BatchInsertServlet")

publicclassBatchInsertServletextendsHttpServlet{

@Override

protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{

...

Stringurl="jdbc:mysql://localhost:3306/jdbc_db?serverTimezone=GMT&characterEncoding=UTF-8&rewriteBatchedStatements=true";

Stringusername="root";//用戶名

Stringpassword="123456";//密碼

conn=DriverManager.getConnection(url,username,password);//獲取數(shù)據(jù)庫(kù)連接

stmt=conn.createStatement();//獲取Statement

conn.setAutoCommit(false);//取消自動(dòng)提交

for(inti=0;i<10000;i++){

Stringsql="insertintousers(username,pwd,email)

"+"values('username"+i+"','password"+i+"','email"+i+"')";

stmt.addBatch(sql);//將SQL語(yǔ)句打包到一個(gè)容器中

}

8.2.2批量插入提升性能批量插入

stmt.executeBatch();//將容器中的SQL語(yǔ)句提交

stmt.clearBatch();//清空容器,為下一次打包做準(zhǔn)備

mit();//所有語(yǔ)句都執(zhí)行完畢后才手動(dòng)提交SQL語(yǔ)句

}

}批量插入注意以下六點(diǎn)。(1)url設(shè)置允許重寫批量提交:rewriteBatchedStatements=true。(2)SQL語(yǔ)名不能以“;”結(jié)束。(3)將SQL語(yǔ)句打包到一個(gè)容器中。(4)將容器中的SQL語(yǔ)句提交。(5)清空容器,為下一次打包做準(zhǔn)備。(6)設(shè)置取消自動(dòng)提交(即手動(dòng)提交數(shù)據(jù))。8.2.3使用CallableStatement訪問(wèn)存儲(chǔ)過(guò)程CallableStatement主要是調(diào)用數(shù)據(jù)庫(kù)中的存儲(chǔ)過(guò)程,在使用CallableStatement時(shí)可以接收存儲(chǔ)過(guò)程的返回值。案例:根據(jù)用戶ID查詢用戶信息創(chuàng)建存儲(chǔ)過(guò)程proc_getUserById(uidint)CREATEPROCEDUREproc_getUserById(uidINT)BEGIN

SELECTusername,pwd,emailFROMusersWHEREuserid=uid;END8.2.3使用CallableStatement訪問(wèn)存儲(chǔ)過(guò)程編寫ProcedureServlet@WebServlet("/ProcedureServlet")

publicclassProcedureServletextendsHttpServlet{

@Override

protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{resp.setContentType("text/html;charset=UTF-8");

PrintWriterout=resp.getWriter();

Stringuid=req.getParameter("uid");

Connectionconn=null;

CallableStatementcs=null;

ResultSetrs=null;

introws=0;

try{

Class.forName("com.mysql.cj.jdbc.Driver");//注冊(cè)MySQL驅(qū)動(dòng)

Stringurl="jdbc:mysql://localhost:3306/jdbc_db?serverTimezone=GMT&characterEncoding=UTF-8";Stringusername="root";//用戶名

Stringpassword="123456";//密碼

8.2.3使用CallableStatement訪問(wèn)存儲(chǔ)過(guò)程

conn=DriverManager.getConnection(url,username,password);//獲取數(shù)據(jù)庫(kù)連接

Stringsql="{callproc_getUserById(?)}";

cs=conn.prepareCall(sql);//獲取CallableStatement

cs.setInt(1,Integer.parseInt(uid));

rs=cs.executeQuery();

if(rs.next()){

Stringname=rs.getString("username");

Stringpwd=rs.getString("pwd");

Stringemail=rs.getString("email");

out.println(name+"--"+pwd+"--"+email);

}

out.flush();

out.close();

}catch(Exceptione){

thrownewRuntimeException(e);

}...

}

}8.2.3使用CallableStatement訪問(wèn)存儲(chǔ)過(guò)程圖

8-5

調(diào)用存儲(chǔ)過(guò)程的運(yùn)行結(jié)果8.2.3使用CallableStatement訪問(wèn)存儲(chǔ)過(guò)程案例:模擬登錄功能定義一個(gè)帶輸出參數(shù)的存儲(chǔ)過(guò)程,輸出參數(shù)前添加OUT關(guān)鍵字,輸入?yún)?shù)可以省略,默認(rèn)是INCREATEPROCEDUREproc_login(unameVARCHAR(50),upwdVARCHAR(50),OUTcountINT)BEGIN SELECTCOUNT(*)intocountFROMusersWHEREusername=unameANDpwd=upwd;END編寫ProcedureOutParamServlet類8.2.3使用CallableStatement訪問(wèn)存儲(chǔ)過(guò)程@WebServlet("/ProcedureOutParamServlet")

publicclassProcedureOutParamServletextendsHttpServlet{

@Override

protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{

...

Stringname=req.getParameter("username");

Stringpwd=req.getParameter("password");

Connectionconn=null;

CallableStatementcs=null;

introws=0;

try{

Class.forName("com.mysql.cj.jdbc.Driver");//注冊(cè)MySQL驅(qū)動(dòng)

Stringurl="jdbc:mysql://localhost:3306/jdbc_db?serverTimezone=GMT&characterEncoding=UTF-8";

Stringusername="root";//用戶名

Stringpassword="123456";//密碼

8.2.3使用CallableStatement訪問(wèn)存儲(chǔ)過(guò)程

conn=DriverManager.getConnection(url,username,password);//獲取數(shù)據(jù)庫(kù)連接

Stringsql="{callproc_login(?,?,?)}";

cs=conn.prepareCall(sql);//獲取CallableStatement

cs.setString(1,name);

cs.setString(2,pwd);

cs.registerOutParameter(3,Types.INTEGER);//參數(shù)2:指定輸出參數(shù)的類型

cs.execute();

intres=cs.getInt(3);

if(res>0){

System.out.println("登錄成功");

}else{

System.out.println("登錄失敗");

}

}catch(Exceptione){

thrownewRuntimeException(e);

}...

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論