JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState

JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState

ID:77513740

大小:529.05 KB

页数:13页

时间:2022-01-25

JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState_第1页
JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState_第2页
JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState_第3页
JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState_第4页
JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState_第5页
JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState_第6页
JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState_第7页
JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState_第8页
JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState_第9页
JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState_第10页
资源描述:

《JavaEEWEB工程师培训-JDBC+Servlet+JSP整合开发之03JDBCState》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、编号:时间:2021年X月X日书山有路勤为径,学海无涯苦作舟页码:第#页共13页JavaEEWEB工程师培训-JDBC+Se「vlet+JSP整合开发之03JDBCStatement1)上季我们建立了与数据库的连接,本季我们将对数据库进行操作使用Statement执行DDL、使用Statement执行DML,常用的插入、更新、删除及查询数据哈~•Statement简介-Statement提供了•个操作数据库语句的功能,可通过它来创建表、插入记录、修改记录、删除记录等操作•获得Statement-可以从数据库连接Connection中获得StatementConnectionconn=newC

2、onnectionUtil().getConnection();Statementstmt=conn.createStatement();ConnectionUtil.javapackagecom.michael.jdbc;importjava.sqLConnection;importjava.sqLDriverManager;importjava.util.Properties;publicclassConnectionUtil{〃第i种方法publicConnectiongetConnection(){Connectionconn=null;try(//Class.forName加载驱动

3、Class.forName(',com.mysql.jdbc.D^ver,,);//DriverManager获得连接conn=DriverManager.getConnection(Hjdbc:mysql://localhost:3306/jdbc_db,,/nroot,,/,mysqladmin");returnconn;}catch(Exceptione){e.printStackTrace();}returnnull;}〃第二种方法publicConnectiongetConnection(StringdnverzStringurl,Stringuser,Stringpassword

4、){Connectionconn=null;try(//Class.forName加载驱动第2贞共13页编号:时间:2021年X月X日书山有路勤为径,学海无涯苦作舟页码:第#页共13页Class.forName(driver);//DriverManager获得连接conn=DriverManager.getConnection(url/userzpassword);returnconn;}catch(Exceptione){e.printStackTrace();}returnnull;)〃第三种方法publicConnectionopenConnection(){Stringdriver

5、=,,H;Stringurl=,n';Stringuser=,,n;Stringpassword=,,H;Propertiesprop=newProperties();Connectionconn=null;try(〃加载属性文件prop.load(this.getClass().getClassLoader().getResourceAsStream("DBConfig.properties'1));driver=prop.getProperty(,,dnver,');url=prop.getProperty(,,urr,);user=prop.getProperty(,,user");p

6、assword=prop.getProperty(,,passwordn);//Class.forName加载驱动Class.forName(driver);//DriverManager获得连接conn=DriverManager.getConnection(url/userzpassword);returnconn;}catch(Exceptione){e.printStackTrace();}returnnull;}第2贞共13页编号:时间:2021年X月X日书山有路勤为径,学海无涯苦作舟页码:第#页共13页Teststatement,javapackagecom.michael.jd

7、bc;importjava.sqLConnection;importjava.sqLSQLException;importjava.sqLStatement;publicclassTeststatement{publicstaticvoidgetStatement(){Connectionconn=newConnectionlltil().openConnection();try(Statementstmt=

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。