版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
課程回mysql默認(rèn)值:default默認(rèn)值 notnull唯一:primarykey(非空+唯一)自增長:auto_increment外鍵:foreign 交叉連接(產(chǎn)生笛卡爾積:原因:連接條件不足夠)表數(shù)量-inner[]null。rightouternull。--創(chuàng)建過程語delimetercreateprocedure名稱(IN/OUT/INOUT 參數(shù)名稱參數(shù)類型)sqlend--調(diào)用過CALL過程名稱(實(shí)際參數(shù));今天的目標(biāo):jdbc基礎(chǔ)jdbc之前操作數(shù)通過mysql的客戶端工具,登錄數(shù)據(jù)庫服務(wù)器(mysql-uroot-psql什么是java代碼(程序)sql語句的技術(shù),就是jdbc使用jdbc發(fā)送sql前IP地址@authorpublicclassDemo1privateStringurl= privateStringuser"root";//privateStringpassword=*法*@throwspublicvoidtest1()throwsDriverdrivernewcom.mysql.jdbc.Driver(//Driverdriverneworg.gjt.mm.mysql.Driver(Propertiesprops=newProperties();props.setProperty("user",user);props.setProperty("password",password);Connectionconn=driver.connect(url,} @throwspublicvoidtest2()throwsDriverdriver=new//Driverdriver2=new Connectionconn=DriverManager.getConnection(url,user,password);}推薦使用加載驅(qū)動(dòng)程序類 @throwspublicvoidtest3()throws//Driverdriver=new //Driverdriver2=new Connectionconn=DriverManager.getConnection(url,user,password);}}JDBC接口的 和|Driverjava|connect(url, url:URLjdbc協(xié)議:數(shù)據(jù)庫子協(xié)議://主機(jī):端口/userpassword|-DriverManager類:驅(qū)動(dòng)管理器類,用于管理所有的驅(qū)動(dòng)程 :驅(qū)動(dòng)類對(duì)|-Connection |Connectionjava|StatementcreateStatement()Statement- |CallableStatementprepareCall(Stringsql)CallableStatement|Statementsql|intexecuteUpdate(String sql語句- sql語句|intexecuteUpdate()sql語句|-ResultSet sql語句|-CallableStatement接口:用于執(zhí)行過程的sql語句(call|-ResultSet :調(diào)用過程的方|ResultSet|booleannext()|-getXX():Statementsql語執(zhí)行DDL語*執(zhí)行DDL語句(創(chuàng)建表publicvoidtest1(){Statementstmt=null;Connectionconn=null;try{ 程conn=DriverManager.getConnection(url,user,stmt=Stringsql="CREATETABLEstudent(idINTPRIMARYKEYAUTO_INCREMENT,NAMEVARCHAR(20),genderVARCHAR(2))";intcount=}catch(Exceptione){thrownew}try{}catch(SQLExceptione){thrownew}try{}catch(SQLExceptione){thrownew}}}執(zhí)行DML語@authorpublicclassDemo2privateStringurl=privateStringuser=privateStringpassword=*publicvoidtestInsert(){Connectionconn=null;Statementstmt=null;try{conn=stmt=Stringsql"INSERTINTOstudent(NAME,genderVALUES('李四','女intcount=}catch(Exceptione){thrownew}try{}catch(SQLExceptione){thrownew}try{}catch(SQLExceptione){thrownewJdbcUtil.close(conn,stmt);}}*publicvoidtestUpdate(){Connectionconn=null;Statementstmt=null;Stringname陳六intid=try conn=DriverManager.getConnection(url,user,conn=stmt=Stringsql="UPDATEstudentSETNAME='"+name+"'WHEREid="+id+"";intcount=}catch(Exceptione){thrownew}try{}catch(SQLExceptione){thrownew}try{}catch(SQLExceptione){thrownewJdbcUtil.close(conn,stmt);}}*publicvoidtestDelete(){Connectionconn=null;Statementstmt=null;intid=try conn=DriverManager.getConnection(url,user,conn=stmt=Stringsql="DELETEFROMstudentWHEREid="+id+"";intcount=}catch(Exceptione){thrownew}try{}catch(SQLExceptione){thrownew}try{}catch(SQLExceptione){thrownewJdbcUtil.close(conn,stmt);}}}執(zhí)行DQL語@authorpublicclassDemo3publicvoidtest1(){Connectionconn=null;Statementstmt=null;conn=stmt=Stringsql="SELECT*FROMResultSetrs=/*booleanflag=flag=rs.next();flag=rs.next();intid=Stringname=rs.getString(2);Stringgender=rs.getString(3);
intid=Stringname=rs.getString("name");Stringgender=rs.getString("gender");intid=Stringname=rs.getString("name");Stringgender=rs.getString("gender");}}catch(Exceptione){thrownewJdbcUtil.close(conn,}}}PreparedStatementsql語publicclassDemo1*publicvoidtestInsert(){Connectionconn=null;PreparedStatementstmt=null;try{conn=
Stringsql"INSERTINTOstudent(NAME,genderVALUES(stmt=*從1stmt.setString(1李四stmt.setString(2男intcount=}catch(Exceptione){thrownew}finallyJdbcUtil.close(conn,}}*publicvoidtestUpdate(){Connectionconn=null;PreparedStatementstmt=null;try{conn=Stringsql"UPDATEstudentSETNAME=WHEREid=?符stmt=*從1stmt.setString(1王五");stmt.setInt(2,9);intcount=}catch(Exceptione){thrownew}finallyJdbcUtil.close(conn,}}*publicvoidtestDelete(){Connectionconn=null;PreparedStatementstmt=null;try{conn=Stringsql"DELETEFROMstudentWHEREidstmt=*從1stmt.setInt(1,intcount=}catch(Exceptione){thrownew}finallyJdbcUtil.close(conn,}}*publicvoidtestQuery(){Connectionconn=null;PreparedStatementstmt=null;ResultSetrs=null;tryconn=Stringsql="SELECT*FROMstmt=rs=intid=Stringname=rs.getString("name");Stringgender=rs.getString("gender");}}catch(Exceptione){thrownew}finally}}}1)語法不同:PreparedStatementsqlStatmentsql2)效率不同:PreparedStatement可以使用sql緩存區(qū),效率比Statment高3)PreparedStatementsqlStatmentsql注入。CallableStatement執(zhí)行過@authorpublicclassDemo1**CALLpublicvoidtest1(){Connectionconn=null;CallableStatementstmt=ResultSetrs=null;try{conn=Stringsql"CALLpro_findById(可以執(zhí)行預(yù)編譯的stmt=stmt.setInt(16);rs=stmt.executeQuery();//注意:所有調(diào) intid=Stringname=rs.getString("name");Stringgender=rs.getString("gender");}}catch(Exceptione){thrownew}finallyJdbcUtil.close(conn,stmt}} 過CALLpublicvoidtest2(){Connectionconn=null;CallableS
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026年七夕節(jié)的文化碰撞與現(xiàn)代化
- 2026年快樂元旦兒童插畫故事
- 2026年合肥高新區(qū)祥生云境幼兒園招聘2名筆試備考題庫及答案解析
- 2026甘肅西北師范大學(xué)考核招聘博士研究生191人考試備考試題及答案解析
- 2026上半年云南事業(yè)單位聯(lián)考德宏州招聘教師214人考試備考試題及答案解析
- 2026四川德陽市城鎮(zhèn)公益性崗位招聘1人(區(qū)委黨校)筆試備考題庫及答案解析
- 2026陜西西安電子科技大學(xué)空間科學(xué)與技術(shù)學(xué)院外聘人員一般崗位招聘考試參考題庫及答案解析
- 2026廣西旅發(fā)大健康產(chǎn)業(yè)集團(tuán)有限公司招聘16人考試參考題庫及答案解析
- 2026新疆恒海國有資產(chǎn)經(jīng)營有限公司招聘7人筆試備考試題及答案解析
- 2026重慶科學(xué)城金鳳實(shí)驗(yàn)學(xué)校招聘4人筆試備考題庫及答案解析
- 2026年維修工崗位面試題庫含答案
- 2026年溫州市1.5模高三語文試題作文題目解析及3篇范文:打扮自己與打扮大地
- 2026年湘西民族職業(yè)技術(shù)學(xué)院單招職業(yè)技能筆試參考題庫含答案解析
- 2025-2026學(xué)年教科版(新教材)小學(xué)科學(xué)三年級(jí)下冊《昆蟲的一生》教學(xué)設(shè)計(jì)
- 2025年12月福建廈門市鷺江創(chuàng)新實(shí)驗(yàn)室管理序列崗位招聘8人參考題庫附答案
- 化工工藝安全管理與操作手冊
- 規(guī)范外匯交易管理制度
- 高考英語讀后續(xù)寫技巧總結(jié)
- 2025年下半年河南鄭州市住房保障和房地產(chǎn)管理局招聘22名派遣制工作人員重點(diǎn)基礎(chǔ)提升(共500題)附帶答案詳解
- 維修事故協(xié)議書
- 2025ESC+EAS血脂管理指南要點(diǎn)解讀課件
評(píng)論
0/150
提交評(píng)論