当前位置: 首页 > news >正文

班级网站建设淘宝网站都是怎么做的吗

班级网站建设,淘宝网站都是怎么做的吗,seo怎么学在哪里学,桥梁建设网站/** ####################################数据库的连接池学习################################# * * * #####数据库连接池 1. 数据库的连接对象创建工作#xff0c;比较消耗性能。 2.一开始现在内存中开辟一块空间#xff08;集合#xff09; #xff0c; 一开… /** ####################################数据库的连接池学习################################# * * * #####数据库连接池 1. 数据库的连接对象创建工作比较消耗性能。 2.一开始现在内存中开辟一块空间集合 一开先往池子里面放置 多个连接对象。 后面需要连接的话直接从池子里面去。不要去自己创建连接了。 使用完毕 要记得归还连接。确保连接对象能循环利用。 ![icon](img/img11.png)###自定义数据库连接池 * 代码实现* 出现的问题1. 需要额外记住 addBack方法2. 单例。3. 无法面向接口编程。 UserDao dao new UserDaoImpl();dao.insert();DataSource dataSource new MyDataSource();因为接口里面没有定义addBack方法。 4. 怎么解决? 以addBack 为切入点。###解决自定义数据库连接池出现的问题。 由于多了一个addBack 方法所以使用这个连接池的地方需要额外记住这个方法并且还不能面向接口编程。 我们打算修改接口中的那个close方法。 原来的Connection对象的close方法是真的关闭连接。 打算修改这个close方法以后在调用close 并不是真的关闭而是归还连接对象。* * * ####开源连接池#### DBCP 1. 导入jar文件 2. 不使用配置文件* public void testDBCP01(){Connection conn null;PreparedStatement ps null;try {//1. 构建数据源对象BasicDataSource dataSource new BasicDataSource();//连的是什么类型的数据库 访问的是哪个数据库 用户名 密码。。//jdbc:mysql://localhost/bank 主协议子协议 ://本地/数据库dataSource.setDriverClassName(com.mysql.jdbc.Driver);dataSource.setUrl(jdbc:mysql://localhost/bank);dataSource.setUsername(root);dataSource.setPassword(root);//2. 得到连接对象conn dataSource.getConnection();String sql insert into account values(null , ? , ?);ps conn.prepareStatement(sql);ps.setString(1, admin);ps.setInt(2, 1000);ps.executeUpdate();} catch (SQLException e) {e.printStackTrace();}finally {JDBCUtil.release(conn, ps);}}* * * ####使用配置文件方式Connection conn null;PreparedStatement ps null;try {BasicDataSourceFactory factory new BasicDataSourceFactory();Properties properties new Properties();InputStream is new FileInputStream(src//dbcpconfig.properties);properties.load(is);DataSource dataSource factory.createDataSource(properties);//2. 得到连接对象conn dataSource.getConnection();String sql insert into account values(null , ? , ?);ps conn.prepareStatement(sql);ps.setString(1, liangchaowei);ps.setInt(2, 100);ps.executeUpdate();} catch (Exception e) {e.printStackTrace();}finally {JDBCUtil.release(conn, ps);}* *###################配置文件模板##################################################*#连接设置 driverClassNamecom.mysql.jdbc.Driver urljdbc:mysql://localhost:3306/bank usernameroot passwordroot#!-- 初始化连接 -- initialSize10#最大连接数量 maxActive50#!-- 最大空闲连接 -- maxIdle20#!-- 最小空闲连接 -- minIdle5#!-- 超时等待时间以毫秒为单位 6000毫秒/1000等于60秒 -- maxWait60000#JDBC驱动建立连接时附带的连接属性属性的格式必须为这样[属性名property;] #注意user 与 password 两个属性会被明确地传递因此这里不需要包含他们。 connectionPropertiesuseUnicodetrue;characterEncodinggbk#指定由连接池所创建的连接的自动提交auto-commit状态。 defaultAutoCommittrue#driver default 指定由连接池所创建的连接的事务级别TransactionIsolation。 #可用值为下列之一详情可见javadoc。NONE,READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE defaultTransactionIsolationREAD_UNCOMMITTED########################################################################################* * ####################C3P0知识点##################################################################C3P0拷贝jar文件 到 lib目录###不使用配置文件方式Connection conn null;PreparedStatement ps null;try {//1. 创建datasourceComboPooledDataSource dataSource new ComboPooledDataSource();//2. 设置连接数据的信息dataSource.setDriverClass(com.mysql.jdbc.Driver);//忘记了--- 去以前的代码 --- jdbc的文档dataSource.setJdbcUrl(jdbc:mysql://localhost/bank);dataSource.setUser(root);dataSource.setPassword(root);//2. 得到连接对象conn dataSource.getConnection();String sql insert into account values(null , ? , ?);ps conn.prepareStatement(sql);ps.setString(1, admi234n);ps.setInt(2, 103200);ps.executeUpdate();} catch (Exception e) {e.printStackTrace();}finally {JDBCUtil.release(conn, ps);}######使用配置文件方式#####c3p0-config配置文件xml文件。名字不可以改变?xml version1.0 encodingUTF-8? c3p0-config!-- default-config 默认的配置 --default-configproperty namedriverClasscom.mysql.jdbc.Driver/propertyproperty namejdbcUrljdbc:mysql://localhost/bank/propertyproperty nameuserroot/propertyproperty namepasswordroot/propertyproperty nameinitialPoolSize10/propertyproperty namemaxIdleTime30/propertyproperty namemaxPoolSize100/propertyproperty nameminPoolSize10/propertyproperty namemaxStatements200/property/default-config!-- This app is massive! --named-config nameoracle property nameacquireIncrement50/propertyproperty nameinitialPoolSize100/propertyproperty nameminPoolSize50/propertyproperty namemaxPoolSize1000/property!-- intergalactoApp adopts a different approach to configuring statement caching --property namemaxStatements0/property property namemaxStatementsPerConnection5/property!-- hes important, but theres only one of him --user-overrides usermaster-of-the-universe property nameacquireIncrement1/propertyproperty nameinitialPoolSize1/propertyproperty nameminPoolSize1/propertyproperty namemaxPoolSize5/propertyproperty namemaxStatementsPerConnection50/property/user-overrides/named-config/c3p0-config#####代码部分//默认会找 xml 中的 default-config 分支。 public class C3P0Demo02 {Testpublic void testC3P0(){Connection conn null;PreparedStatement ps null;try {//就new了一个对象。在这种情况下c3p0会直接找到c3p0-config.xml文件//并且在c3p0-config.xml文件中默认的找到 default-config配置ComboPooledDataSource dataSource new ComboPooledDataSource();//ComboPooledDataSource dataSource new ComboPooledDataSource(oracle);//找到c3p0-config.xml文件中默认的找到named-config nameoracle的配置//2. 得到连接对象conn dataSource.getConnection();String sql insert into account values(null , ? , ?);ps conn.prepareStatement(sql);ps.setString(1, wangwu2);ps.setInt(2, 2600);ps.executeUpdate();} catch (Exception e) {e.printStackTrace();}finally {JDBCUtil.release(conn, ps);}} }###########################################################################################* ###########DBUtils###增删改 //dbutils 只是帮我们简化了CRUD 的代码 但是连接的创建以及获取工作。 不在他的考虑范围QueryRunner主要是这个类QueryRunner queryRunner new QueryRunner(new ComboPooledDataSource());//增加 //queryRunner.update(insert into account values (null , ? , ? ), aa ,1000);//删除 //queryRunner.update(delete from account where id ?, 5);//更新 //queryRunner.update(update account set money ? where id ?, 10000000 , 6);* * * * * * ######查询 1. 直接new接口的匿名实现类QueryRunner queryRunner new QueryRunner(new ComboPooledDataSource());Account account queryRunner.query(select * from account where id ?, new ResultSetHandlerAccount(){Overridepublic Account handle(ResultSet rs) throws SQLException {Account account new Account();while(rs.next()){String name rs.getString(name);int money rs.getInt(money);account.setName(name);account.setMoney(money);}return account;}}, 6);System.out.println(account.toString());2. 直接使用框架已经写好的实现类。 * 查询单个对象QueryRunner queryRunner new QueryRunner(new ComboPooledDataSource());//查询单个对象Account account queryRunner.query(select * from account where id ?, new BeanHandlerAccount(Account.class), 8);* 查询多个对象QueryRunner queryRunner new QueryRunner(new ComboPooledDataSource());ListAccount list queryRunner.query(select * from account ,new BeanListHandlerAccount(Account.class));######ResultSetHandler 常用的实现类(重点) 以下两个是使用频率最高的BeanHandler, 查询到的单个数据封装成一个对象BeanListHandler, 查询到的多个数据封装 成一个List对象------------------------------------------ArrayHandler, 查询到的单个数据封装成一个数组ArrayListHandler, 查询到的多个数据封装成一个集合 集合里面的元素是数组。 MapHandler, 查询到的单个数据封装成一个mapMapListHandler,查询到的多个数据封装成一个集合 集合里面的元素是map。 ColumnListHandler KeyedHandler ScalarHandler##数据连接池* DBCP不使用配置使用配置* C3P0不使用配置使用配置 必须掌握* 自定义连接池 装饰者模式##DBUtils 简化了我们的CRUD 里面定义了通用的CRUD方法。 queryRunner.update();queryRunner.query* * * * * */   转载于:https://www.cnblogs.com/byczyz/p/11343575.html
http://www.huolong8.cn/news/70509/

相关文章:

  • 免费做网站方案一站式做网站哪家强
  • 网站推广软文虐做视频网站
  • 零基础学做网站的书河南建设信息网一体化
  • 自己制作网站做外贸赚钱吗WordPress手机用户提示登录
  • 微网站的案例在线做动漫图的网站
  • 有什么字体设计网站企业微信网站建设方案模板下载
  • 四川住房和城乡建设部官方网站企业整合营销系统
  • 什么网站做装修公司广告比较好画册排版设计网站
  • 网站建设要多久广州网络推广公司电话
  • 潍坊建网站的西安网站建设建站系统
  • 为什么网站显示建设中wordpress太臃肿
  • 丰台企业网站建设泰安网站建设总结
  • 做枪网站北京海淀中关村找工作网站
  • 建网站需要什么手续做招商类型的网站
  • phpcms套好的网站 放到空间上 后台打开的验证码不能显示普通人怎么样做网站
  • 网站模板开发主要作用wordpress 用户评分
  • 怎么建设自己网站的后台徐州建站网站模板
  • 衡阳公司做网站百度推广网页版
  • 做学校网站用什么模版seo首页优化
  • ps专门做兼职的网站有哪些宁德时代网站哪个公司做的
  • 网站图片代码怎么做阿里巴巴每平每屋设计家官网
  • vs网站开发杭州旅游团购网站建设
  • 南宁免费自助建站模板珠海市 网站建设
  • 建网站与建网页的区别汕头网页网站制作
  • 网站策划书模板范文网站建设进展报告
  • 网站空间过期网络科技有限公司 网站建设
  • 网站设计公司模板下载网站百度推广方案
  • 宁德网站设计做网站交付标准
  • 电商网站有哪些特色商城类网站建设
  • 互联网站源码安徽建设项目建设工程在线