如何使用sql创建JDBC连接池? [英] how to create JDBC connection pool using sql?

查看:84
本文介绍了如何使用sql创建JDBC连接池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在java中实现连接池?

给我帮助代码..

how to implement connection pooling in java?
give me helping code..

推荐答案

java提供DataSource类javax.sql。 DataSource,使用它我们可以查找在应用程序服务器中创建的JNDI。



无需使用java创建池。可以在应用程序服务器上创建池,并使用JNDI名称访问它。



如果你真的想用java创建自己的连接池,你可以做所以,通过将所有require参数放在属性文件中,如最大连接数,最小连接数,数据库连接数和最大理想时间数。



然后编写代码,就像在给定时间需要多少连接,创建可能连接并将连接ID​​(供您参考)和连接对象放在hashmap中,这里您需要跟踪用户何时发出请求时使用的连接。也是它理想的时间。当最小连接繁忙时,您需要创建一个新连接以满足更多需求并将其提供给用户。



上述提及的详细信息仅供参考。



但我建议使用服务器提供的连接池设施,而不是自己创建。



希望这些信息可以帮到你。



问候,

Panduranga。
java Provide DataSource class javax.sql.DataSource, using this we can look up for the JNDI created in the application server.

No need to create the pool using java. the pool can be created on the application server, and access it using the JNDI name.

If you really want to create your own connection pool using java, you an do so, by putting all the require parameters in a property file like max connections, min connections, DB connection details, and the max ideal time.

And then write a code, like at a given time how many connections are required, create that may connection and put the connection id (for your reference) and connection object in hashmap, here you need to keep track which connection is used, whenever user makes the request. and also its ideal time. When the min connection are busy then you need to create a new connection for more demand and give it to user.

The above mention details is only an overview.

But i suggest to use the connection pool facility provided by the server rather than creating your own.

Hope this info helps you.

Regards,
Panduranga.


这篇关于如何使用sql创建JDBC连接池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆