在dbcp中使用PreparedStatement池 [英] Using PreparedStatement pooling in dbcp

查看:120
本文介绍了在dbcp中使用PreparedStatement池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释如何使用完全准备好的使用dbcp的连接池吗? (如果可能,请提供一些示例代码).我已经弄清楚了如何打开它-将KeyedObjectPoolFactory传递给PoolableConnectionFactory. 但是,在那之后应该如何定义特定的准备好的语句呢? 现在,我仅使用PoolingDataSource从池中获取连接.如何使用池中准备好的语句?

Can someone explain how exactly prepared connection pooling using dbcp can be used? (with some example code if possible). I've figured out how to turn it on - passing a KeyedObjectPoolFactory to the PoolableConnectionFactory. But how should the specific prepared statements be defined after that? Right now I'm only using a PoolingDataSource to get connections from the pool. How do I use the prepared statements from the pool?

推荐答案

在谈论从池中获取连接与获取非池中"连接相比,您的代码是否有任何更改:)?我敢打赌你不会.与准备好的语句相同.您的代码不应更改.因此,对此没有有用的代码示例.

Well talking about getting connection from the pool vs getting "not-pooled" connection, do you have any change in your code :)? I bet you do not. Same way with prepared statements. Your code should not change. So, there is no useful code example to this.

您应该阅读有关JDBC数据源实现的文档,并了解开发人员对池的评价.没有其他可靠信息的来源.

You should read docs for your JDBC Datasource implementation and see what developers have to say about pooling. There is no other source of reliable info on this.

此处: 该组件还具有池PreparedStatement的功能.启用后,将为每个Connection创建一个语句池,并通过以下方法之一创建的PreparedStatement将被池化:

From here: This component has also the ability to pool PreparedStatements. When enabled a statement pool will be created for each Connection and PreparedStatements created by one of the following methods will be pooled:

* public PreparedStatement prepareStatement(String sql)
* public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)

因此,您只需继续使用prepareStatement()调用,理论上您的dbcp将负责缓冲池(即,如果您尝试创建从用户u选择*,其中u.name如:id",它将尝试首先在池中找到此语句)

So, you just keep using prepareStatement() call and your dbcp will in theory take care of pooling (i.e. if you are trying to create "select * from users u where u.name like :id", it will try to find this statement in the pool first)

这篇关于在dbcp中使用PreparedStatement池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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