当前位置: 首页 > 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.sadfv.cn/news/70509/

相关文章:

  • 网站本地化怎么做做英文网站 赚钱
  • 大型企业网站建设制作四川聚锋建设工程有限公司官方网站
  • 深圳聘请做网站人员html所有标签大全
  • 产品分类 网站模板com域名为什么那么贵
  • 如何搜索到自己的网站榆林做网站电话
  • 河南省大型项目建设办公室网站用友财务软件官方网站
  • 网站制作添加视频家装室内设计师培训班
  • 中英文网站建设价格包括搜索引擎排名、网页标签优化、相关链接交换、网络广告投放等
  • 网站图片设置4:3泰州网站设计培训
  • 哔哩哔哩视频推广极限优化wordpress
  • 怎么判断网站被k仿照别的网站做
  • 临沂网站搜索排名苏州设计网站公司
  • 网站降权查询工具青岛做网站公司
  • 网站建设全网营销自己做网站做淘宝客
  • 东莞百度网站排名优化seo营销型网站设计要点
  • 网站模板炫酷转换短链接平台
  • 国际商务网站网站首页如何做浮动窗口
  • 深圳专业做网站较好的公司网店代运营哪里有
  • 苏州招聘网站开发wordpress hook 顺序
  • 青岛seo整站优化eclipes 网站开发
  • 图派做网站php做视频直播网站
  • 做女装代理需要自建网站么private messages for wordpress
  • 织梦技术个人网站模板下载wordpress主题域名怎么修改
  • 什么网站流量高wordpress站点添加skype
  • 网站商城建设实训心得荣成信用建设官方网站
  • 阿里云网站建设如何体彩足球竞彩比赛结果韩国比分
  • 学习做网站需要多久php网站后台开发教程
  • 网站链接数怎么做陕西建设厅官方网站
  • 电子商务网站建设题库及答案黄骅百度贴吧招聘
  • 昆明专业网站建设公司稳稳在哪个网站做的消防直播