准备好的语句以及连接池

编程入门 行业动态 更新时间:2024-10-10 19:21:21
本文介绍了准备好的语句以及连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

准备好的语句以及连接池

本文发布于:2023-11-10 14:26:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   连接池

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!