欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBC Statement6299.docx

    • 资源ID:62819604       资源大小:931.77KB        全文页数:19页
    • 资源格式: DOCX        下载积分:10金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要10金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBC Statement6299.docx

    Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之03.JDBC Statement(1)上季我们建建立了与与数据库库的连接接,本季季我们将将对数据据库进行行操作使使用Sttateemennt 执执行DDDL、使使用Sttateemennt 执执行DMML,常常用的插插入、更更新、删删除及查查询数据据哈 Staatemmentt 简介介Stattemeent 提供了了一个操操作数据据库语句句的功能能,可通通过它来来创建表表、插入入记录、修修改记录录、删除除记录等等操作 获得SStattemeent可以从数数据库连连接Coonneectiion中中获得SStattemeentConneectiion connn = neew CConnnecttionnUtiil().geetCoonneectiion();      Staatemmentt sttmt = cconnn.crreatteSttateemennt();ConneectiionUUtill.jaavapackaage comm.miichaael.jdbbc;      impportt jaava.sqll.Coonneectiion;     immporrt jjavaa.sqql.DDrivverMManaagerr;     iimpoort javva.uutill.Prropeertiies;     puubliiccllasss CoonneectiionUUtill                 /第一一种方法法                pubblicc Coonneectiion gettConnnecctioon()                           Connnecctioon cconnn = nulll;                           trry                                      /Claass.forrNamme加载载驱动                                      Claass.forrNamme(""comm.myysqll.jddbc.Driiverr");                                     /DriiverrMannageer获得得连接                                      connn = DrriveerMaanagger.gettConnnecctioon(""jdbbc:mmysqql:/loocallhosst:333066/jddbc_db"","rroott",""myssqlaadmiin");                                     rretuurn connn;                            cattch (Exxcepptioon ee)                                      e.priintSStacckTrracee();                                                    rretuurnnnulll;                                /第二二种方法法                pubblicc Coonneectiion gettConnnecctioon(SStriing driiverr,Sttrinng uurl,Strringg usser,Strringg paasswwordd)                           Coonneectiion connn = nuull;                          ttry                                      /Cllasss.foorNaame加加载驱动动                                     Cllasss.foorNaame(driiverr);                                      /DDrivverMManaagerr获得连连接                                     cconnn = DriiverrMannageer.ggetCConnnecttionn(urrl,uuserr,paasswwordd);                                      retturnn coonn;                           caatchh (EExceeptiion e)                                      ee.prrinttStaackTTracce();                                                      retturnnnulll;                                /第第三种方方法                puubliic CConnnecttionn oppenCConnnecttionn()                          SStriing driiverr = ""                          SStriing urll = ""                          SStriing useer = """                           Strringg paasswwordd = ""                          PPropperttiess prrop = nnew Prooperrtiees();                           Connnecctioon cconnn = nulll;                           trry                                      /加载属属性文件件                                     prrop.loaad(tthiss.geetCllasss().gettClaassLLoadder().ggetRResoourcceAssStrreamm("DDBCoonfiig.ppropperttiess");                                     ddrivver = ppropp.geetPrropeertyy("ddrivver"");                                      urll = proop.ggetPProppertty(""urll");                                     usser = ppropp.geetPrropeertyy("uuserr");                                     paasswwordd = proop.ggetPProppertty(""passswoord"");                                      /CClasss.fforNNamee加载驱驱动                                     CClasss.fforNNamee(drriveer);                                     /DriiverrMannageer获得得连接                                      connn = DrriveerMaanagger.gettConnnecctioon(uurl,useer,ppasssworrd);                                     reeturrn cconnn;                            ccatcch (Exccepttionn e)                                       e.pprinntSttackkTraace();                                                      retturnnnulll;                      TestSStattemeent.javvapackaage comm.miichaael.jdbbc;      impportt jaava.sqll.Coonneectiion;     immporrt jjavaa.sqql.SSQLEExceeptiion;     immporrt jjavaa.sqql.SStattemeent;     puubliiccllasss TeestSStattemeent                 puubliicsttatiicvooid gettStaatemmentt()                          CConnnecttionn coonn = nnew ConnnecctioonUttil().oopennConnnecctioon();                           tryy                                       Staatemmentt sttmt = cconnn.crreatteSttateemennt();                                     SSysttem.outt.prrinttln(stmmt);                           caatchh (SSQLEExceeptiion e)                                      / TTODOO Auuto-genneraatedd caatchh bllockk                                     e.priintSStacckTrracee();                                                Main.javvapackaage comm.miichaael.maiin;      impportt coom.mmichhaell.jddbc.ConnnecctioonUttil;     immporrt ccom.micchaeel.jjdbcc.TeestSStattemeent;     puubliiccllasss Maain                 /*                 * pparaam aargss                 */                pubbliccstaaticcvoiid mmainn(Sttrinng arrgs)                            CoonneectiionUUtill cuu = neww CoonneectiionUUtill();                          /第一一种方法法                          SSysttem.outt.prrinttln("第一一种方法法:"+cu.gettConnnecctioon();                           /第二种种方法                           Syysteem.oout.priintlln(""第二种种方法:"+ccu.ggetCConnnecttionn("ccom.myssql.jdbbc.DDrivver"","jddbc:myssql:/llocaalhoost:33006/jjdbcc_dbb",""rooot","myysqlladmmin"");                          /第三三种方法法                          SSysttem.outt.prrinttln("第三三种方法法:"+cu.opeenCoonneectiion();                          TTesttStaatemmentt.geetSttateemennt();                       测试结果: 使用SStattemeent 执行DDDL可以使用用Staatemmentt来执行行一个数数据定义义语句,例例如:创创建一张张表TestSStattemeent.javvapackaage comm.miichaael.jdbbc;      impportt jaava.sqll.Coonneectiion;     immporrt jjavaa.sqql.SSQLEExceeptiion;     immporrt jjavaa.sqql.SStattemeent;     puubliiccllasss TeestSStattemeent                 puubliicsttatiicvooid gettStaatemmentt()                          CConnnecttionn coonn = nnew ConnnecctioonUttil().oopennConnnecctioon();                           tryy                                       Staatemmentt sttmt = cconnn.crreatteSttateemennt();                                     SSysttem.outt.prrinttln(stmmt);                           caatchh (SSQLEExceeptiion e)                                      / TTODOO Auuto-genneraatedd caatchh bllockk                                     e.priintSStacckTrracee();                                                          puubliicsttatiicvooid creeateeTabble()                           /DDLL数据定定义语句句                          CConnnecttionn coonn = nnew ConnnecctioonUttil().oopennConnnecctioon();                           Strringg sqql = "ccreaate tabble CusstommerTTbl(id intt prrimaary keyy auuto_inccremmentt,naame varrchaar(220),emaail varrchaar(220)"                           trry                                      Sttateemennt sstmtt = connn.ccreaateSStattemeent();                                      /执执行SQQL语句句                                     sttmt.exeecutte(ssql);                            ccatcch (SQLLExccepttionn e)                                       / TODDO AAutoo-geenerrateed ccatcch bblocck                                     ee.prrinttStaackTTracce();                           fiinallly                                     iff(coonn!=nuull)                                                tryy                                                            coonn.cloose();                                                 caatchh (SSQLEExceeptiion e)                                                            connn = nuull;                                                          ee.prrinttStaackTTracce();                                                                                                 Main.javvapackaage comm.miichaael.maiin;      impportt coom.mmichhaell.jddbc.ConnnecctioonUttil;     immporrt ccom.micchaeel.jjdbcc.TeestSStattemeent;     puubliiccllasss Maain                 /*                 * pparaam aargss                 */                pubbliccstaaticcvoiid mmainn(Sttrinng arrgs)                            CoonneectiionUUtill cuu = neww CoonneectiionUUtill();                          /第一一种方法法                          SSysttem.outt.prrinttln("第一一种方法法:"+cu.gettConnnecctioon();                           /第二种种方法                           Syysteem.oout.priintlln(""第二种种方法:"+ccu.ggetCConnnecttionn("ccom.myssql.jdbbc.DDrivver"","jddbc:myssql:/llocaalhoost:33006/jjdbcc_dbb",""rooot","myysqlladmmin"");                          /第三三种方法法                          SSysttem.outt.prrinttln("第三三种方法法:"+cu.opeenCoonneectiion();                          TTesttStaatemmentt.geetSttateemennt();                           TesstSttateemennt.ccreaateTTablle();                       测试结果:  使用SStattemeent 执行DDML更新 Innserrt TestSStattemeent.javvapackaage comm.miichaael.jdbbc;      impportt jaava.sqll.Coonneectiion;     immporrt jjavaa.sqql.SSQLEExceeptiion;     immporrt jjavaa.sqql.SStattemeent;     puubliiccllasss TeestSStattemeent                 puubliicsttatiicvooid gettStaatemmentt()                          CConnnecttionn coonn = nnew ConnnecctioonUttil().oopennConnnecctioon();                           tryy                                       Staatemmentt sttmt = cconnn.crreatteSttateemennt();                                     SSysttem.outt.prrinttln(stmmt);                           caatchh (SSQLEExceeptiion e)                                      / TTODOO Auuto-genneraatedd caatchh bllockk                                     e.priintSStacckTrracee();                                                          puubliicsttatiicvooid creeateeTabble()                           /DDLL数据定定义语句句                          CConnnecttionn coonn = nnew ConnnecctioonUttil().oopennConnnecctioon();                           Strringg sqql = "ccreaate tabble CusstommerTTbl(id intt prrimaary keyy auuto_inccremmentt,naame varrchaar(220),emaail varrchaar(220)"                           trry                                      Sttateemennt sstmtt = connn.ccreaateSStattemeent();                                      /执执行SQQL语句句                                     sttmt.exeecutte(ssql);                            ccatcch (SQLLExccepttionn e)                                       / TODDO AAutoo-geenerrateed ccatcch bblocck                                     ee.prrinttStaackTTracce();                           fiinallly                                     iff(coonn!=nuull)                                                tryy                                                            coonn.cloose();                                                 caatchh (SSQLEExceeptiion e)                                                            connn = nuull;                                                          ee.prrinttStaackTTracce();                                                                                                           /DDML数数据操作作语句-CRRUD:creeatee、reetriive、uupdaate、ddeleete                ppubllicsstatticvvoidd teestIInseert()                           /DDLL数据定定义语句句                          CConnnecttionn coonn = nnew ConnnecctioonUttil().oopennConnnecctioon();                           Strringg sqql = "iinseert intto CCusttomeerTbbl(nnamee,emmaill) vvaluues('Miichaael'','mmichhaellm')""                           tryy                                       Staatemmentt sttmt = cconnn.crreatteSttateemennt();                                     /执行行SQLL语句                                      stmmt.eexeccuteeUpddatee(sqql);                           caatchh (SSQLEExceeptiion e)                                      / TTODOO Auuto-genneraatedd caatchh bllockk                                     e.priintSStacckTrracee();                          finnallly                                      if(cconnn!=nnulll)                                                trry                                                           cconnn.cllosee();                                                 ccatcch (SQLLExccepttionn e)                                                            coonn = nnulll;                                                           e.pprinntSttackkTraace();                                                                                                Main.javvapackaage comm.miichaael.maiin;      impportt coom.mmichhaell.jddbc.ConnnecctioonUttil;     immporrt ccom.micchaeel.jjdbcc.TeestSStattemeent;     puubliiccllasss Maain                 /*                 * pparaam aargss                 */                pubbliccstaaticcvoiid mmainn(Sttrinng arrgs)                            CoonneectiionUUtill cuu = neww CoonneectiionUUtill();                          /第一一种方法法                          SSysttem.outt.prrinttln("第一一种方法法:"+cu.gettConnnecctioon();                           /第二种种方法                           Syysteem.oout.priintlln(""第二种种方法:"+ccu.ggetCConnnecttionn("ccom.myssql.jdbbc.DDrivver"","jddbc:myssql:/llocaalhoost:33006/jjdbcc_dbb",""rooot","myysqlladmmin"");                          /第三三种方法法                          SSysttem.outt.prrinttln("第三三种方法法:"+cu.opeenCoonneectiion();                          TTesttStaatemmentt.geetSttateemennt();                           /TTesttStaatemmentt.crreatteTaablee();                          TTesttStaatemmentt.teestIInseert();                      测试结果: 

    注意事项

    本文(Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBC Statement6299.docx)为本站会员(you****now)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开