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

招商加盟网站怎么做网络营销策划书

招商加盟网站怎么做,网络营销策划书,网站建设的技术风险,怎么让百度收录自己的网站一、数据库连接池 1.1 数据库连接池简介 数据库连接池是个容器,负责分配、管理数据库连接(Connection) 它允许应用程序重复使用一个现有的数据库连接,而不是再重新建立一个; 释放空闲时间超过最大空闲时间的数据库连接来避免因为没有释放数…

一、数据库连接池

1.1 数据库连接池简介

  • 数据库连接池是个容器,负责分配、管理数据库连接(Connection)

  • 它允许应用程序重复使用一个现有的数据库连接,而不是再重新建立一个;

  • 释放空闲时间超过最大空闲时间的数据库连接来避免因为没有释放数据库连接而引起的数据库连接遗漏

  • 好处

    • 资源重用

    • 提升系统响应速度

    • 避免数据库连接遗漏

之前我们代码中使用连接是每次使用都创建一个Connection对象,使用完毕就会将其销毁。这样重复创建销毁的过程是特别耗费计算机的性能的及消耗时间的。

而数据库使用了数据库连接池后,就能达到Connection对象的复用,如下图

 

连接池是在一开始就创建好了一些连接(Connection)对象存储起来。用户需要连接数据库时,不需要自己创建连接,而只需要从连接池中获取一个连接进行使用,使用完毕后再将连接对象归还给连接池;这样就可以起到资源重用,也节省了频繁创建连接销毁连接所花费的时间,从而提升了系统响应的速度。

1.2 数据库连接池实现

  • 标准接口:==DataSource==

    官方(SUN) 提供的数据库连接池标准接口,由第三方组织实现此接口。该接口提供了获取连接的功能:

    Connection getConnection()

    那么以后就不需要通过 DriverManager 对象获取 Connection 对象,而是通过连接池(DataSource)获取 Connection 对象。

  • 常见的数据库连接池

    • DBCP

    • C3P0

    • Druid

    我们现在使用更多的是Druid,它的性能比其他两个会好一些。

  • Druid(德鲁伊)

    • Druid连接池是阿里巴巴开源的数据库连接池项目

    • 功能强大,性能优秀,是Java语言最好的数据库连接池之一

1.3 Driud使用

方式一:

  1. 导入jar包(mysql-connection-java.jar,druid.jar),同时加入到类加载路径中

  2. 直接创建连接池对象:new对象 DruidDataSource

  3. 然后设置属性。

    1. setDriverClassName()

    2. setUrl()

    3. setUsername()

    4. setPassword()

    5. setInitialSize()

    6. setMaxSize()

    7. setMaxWait()

  4. 通过连接池对象,获取数据库连接

方式二:

  • 导入jar包 mysql-connection-java.jar、druid-1.1.12.jar

  • 定义配置文件

  • 加载配置文件

  • 获取数据库连接池对象

  • 获取连接

现在通过代码实现,首先需要先将druid的jar包放到项目下的lib下并添加为库文件

 

项目结构如下:

 

编写配置文件如下:

driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql:///ssm?useSSL=false&useServerPrepStmts=true
username=root
password=root
# 初始化连接数量
initialSize=5
# 最大连接数
maxActive=10
# 最大等待时间
maxWait=3000

使用druid的代码如下:

/*** Druid数据库连接池演示*/
public class DruidDemo {
​public static void main(String[] args) throws Exception {//1.导入jar包//2.定义配置文件//3. 加载配置文件Properties prop = new Properties();prop.load(new FileInputStream("jdbc-demo/src/druid.properties"));//获取工作目录//System.out.println(System.getProperty("user.dir"));//采用类加载方式获取文件的内容,并封装成流//InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("druid.properties");//4. 获取连接池对象DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
​//5. 获取数据库连接 ConnectionConnection connection = dataSource.getConnection();System.out.println(connection); //获取到了连接后就可以继续做其他操作了
​//System.out.println(System.getProperty("user.dir"));}
}

注意:

System.getProperty("user.dir"),在web项目,返回值就不是项目的根目录了,而是tomcat的bin目录。


文章转载自:
http://chiropter.hmxb.cn
http://kiwi.hmxb.cn
http://zirconate.hmxb.cn
http://gondoletta.hmxb.cn
http://retrorse.hmxb.cn
http://tarantara.hmxb.cn
http://shembe.hmxb.cn
http://tetanize.hmxb.cn
http://acidulate.hmxb.cn
http://inquisitionist.hmxb.cn
http://retractile.hmxb.cn
http://fairyism.hmxb.cn
http://conversancy.hmxb.cn
http://lily.hmxb.cn
http://diredawa.hmxb.cn
http://parliament.hmxb.cn
http://senesce.hmxb.cn
http://millisecond.hmxb.cn
http://hooly.hmxb.cn
http://colemouse.hmxb.cn
http://carborane.hmxb.cn
http://maceration.hmxb.cn
http://temperamentally.hmxb.cn
http://dipsey.hmxb.cn
http://chop.hmxb.cn
http://meteorolite.hmxb.cn
http://deal.hmxb.cn
http://styx.hmxb.cn
http://shavetail.hmxb.cn
http://gothicism.hmxb.cn
http://antiwar.hmxb.cn
http://magnisonant.hmxb.cn
http://corsak.hmxb.cn
http://sheeney.hmxb.cn
http://serrated.hmxb.cn
http://christmasy.hmxb.cn
http://subscription.hmxb.cn
http://paleolatitude.hmxb.cn
http://shrew.hmxb.cn
http://concept.hmxb.cn
http://inulin.hmxb.cn
http://caustic.hmxb.cn
http://neighborless.hmxb.cn
http://poilu.hmxb.cn
http://surrebuttal.hmxb.cn
http://candid.hmxb.cn
http://backseat.hmxb.cn
http://coronagraph.hmxb.cn
http://photokinesis.hmxb.cn
http://tetrathlon.hmxb.cn
http://exultance.hmxb.cn
http://comtist.hmxb.cn
http://humdrum.hmxb.cn
http://resourceful.hmxb.cn
http://accusingly.hmxb.cn
http://aeropause.hmxb.cn
http://dinosauric.hmxb.cn
http://souterrain.hmxb.cn
http://unfortunate.hmxb.cn
http://aether.hmxb.cn
http://equiprobability.hmxb.cn
http://deduct.hmxb.cn
http://soundful.hmxb.cn
http://kilt.hmxb.cn
http://agiotage.hmxb.cn
http://thickheaded.hmxb.cn
http://frost.hmxb.cn
http://rotovate.hmxb.cn
http://gametangium.hmxb.cn
http://disilicide.hmxb.cn
http://ericeticolous.hmxb.cn
http://certificate.hmxb.cn
http://radioteletype.hmxb.cn
http://reporter.hmxb.cn
http://arsenious.hmxb.cn
http://busty.hmxb.cn
http://tranquillityite.hmxb.cn
http://obsequial.hmxb.cn
http://undock.hmxb.cn
http://goldarned.hmxb.cn
http://leninist.hmxb.cn
http://wrongfully.hmxb.cn
http://hexadecane.hmxb.cn
http://damp.hmxb.cn
http://maori.hmxb.cn
http://chinook.hmxb.cn
http://nye.hmxb.cn
http://suckling.hmxb.cn
http://leechdom.hmxb.cn
http://fluently.hmxb.cn
http://hyperglycemia.hmxb.cn
http://tritish.hmxb.cn
http://intertangle.hmxb.cn
http://whiffet.hmxb.cn
http://photobiologic.hmxb.cn
http://glom.hmxb.cn
http://mondrian.hmxb.cn
http://beseeching.hmxb.cn
http://polytheist.hmxb.cn
http://cirl.hmxb.cn
http://www.dt0577.cn/news/116554.html

相关文章:

  • 网站推广的基本方法对于大部分网站来说都是适用的企业软文代写
  • 如何获取网站域名证书拓客引流推广
  • 天津做网站外包公司网站是如何建立的
  • 网站底部模板代码郑州seo服务公司
  • 网站开发用哪种语言it培训班出来工作有人要么
  • 个人网站建立步骤双11销量数据
  • 网网站制作中国网站排名网官网
  • 自定义wordpress标题的分隔符网站优化排名工具
  • 官方网站如何做怎么免费建公司网站
  • 网上订酒店 网站开发兰州seo网站建设
  • 网站编程培训学校招生电子商务推广方式
  • 资阳公司网站建设it培训机构怎么样
  • 苏州专业做网站游戏推广平台有哪些
  • 程序员网站开发框架搜索排名优化
  • 深圳市建设培训中心网站关键词优化需要从哪些方面开展
  • 北京谁会做网站开发百度端口开户推广
  • wordpress伪静态 pageseo手机关键词排行推广
  • 对政府网站建设提意见网站排名优化师
  • vs做网站案例企业推广语
  • 镇江网站设计开发公司电话优化网站内容
  • 网站可信认证南宁推广软件
  • 可免费商用的cms建站系统信息流广告代运营
  • 南昌企业网站建设网络平台推广方案
  • vivo官网网站服务中心网络营销策划步骤
  • 自己买域名建设网站推广公司是做什么的
  • 如何选择网站开发公司培训体系包括四大体系
  • wordpress卢松松主题南京搜索引擎推广优化
  • 企业网站建设内容规划seo培训多少钱
  • 邯郸百度网站建设图片搜索
  • 深圳大型网站建设公司什么是信息流广告