准备好的语句以及连接池 [英] Prepared Statements along with Connection Pooling

查看:122
本文介绍了准备好的语句以及连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对准备语句的一般用法以及连接池有疑问。

I have a question regarding general use of Prepared Statement along with connection pooling.

准备好的语句通常仅与一个连接相关联。在我们的应用程序中,PreparedStatement是在启动时创建并在稍后执行。

Prepared Statements are generally tied to one connection only.In our application, a PreparedStatement is created at the start up and executed at a later point.

如果在执行某些特定预准备语句时,与准备好的语句关联的连接正忙于执行其他语句比这个必需的语句将如何执行。这个语句是等待连接获得免费还是这个语句将被优先执行?

If at the time of execution of some specific prepared statement, connection associated with the prepared statement is busy executing other statements than how this required statement will get executed.Does this statement will wait for connection to get free or this statement will be given preference in execution?

更新

我已经使用Apache derby数据库跟踪SLEEP()函数测试了这一点,该数据库在类TimeHandlingTest中调用java函数sleep。

I have tested this by following SLEEP() function with Apache derby database which calls java function sleep in class TimeHandlingTest.

CREATE FUNCTION SLEEP()返回INTEGER LANGUAGE JAVA PARAMETER STYLE JAVA NO SQL EXTERNAL NAME'com.derby.test.TimeHandlingTest.sleep';

CREATE FUNCTION SLEEP() RETURNS INTEGER LANGUAGE JAVA PARAMETER STYLE JAVA NO SQL EXTERNAL NAME 'com.derby.test.TimeHandlingTest.sleep';

并制作两个准备好了来自一个连接的语句和来自一个预准备语句的简单sql select和一个简单的sql select与其他语句一起调用sql select sql select花了几乎相同的时间(10s),其中第一个预准备语句正在休眠。这意味着一个连接对象不能用于执行一次不止一个准备好的陈述。如果我错了,请纠正我。

And made two prepared statements from one connection and called Sleep() function from one prepared statement and simple sql select with other.Simple sql select took almost same time(10s) for which first prepared statement was sleeping.This means that one connection object cannot be used for execution by more than one prepared statement at a time.Please correct me if i am wrong.

推荐答案

你不能退货<如果您打算使用 PreparedStatement ,请将code>连接添加到池中。

You can't return the Connection to the pool if you plan on using the PreparedStatement.

换句话说:你只能使用连接构建的 PreparedStatement

In other words: you can only use a PreparedStatement constructed from a Connection that you currently have.

这篇关于准备好的语句以及连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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