我正在使用Tomcat 6作为容器创建一个Web应用程序,我正在尝试使用连接池.我使用的jdbc驱动程序是jtds-1.2.2.
当驱动程序jar放在下面时${Catalina_Home}/lib,池工作正常,但我的托管服务提供商不允许我这样做.
当驱动程序被放入时,我得到一个CNF-Exception WEB-INF/lib.
有人可以提供一个我不需要访问tomcat安装的解决方案吗?
您好我正在尝试使用Oracle 11g进行数据库驻留连接池.现在我想到的一个问题是,如果后端有1个数据库服务器.我的数据库服务器在给定时刻可以处理多少个并发请求,它是一个还是同时多个.
为了解释我的问题,如果Client1请求前100个结果的选择查询,并且Client2请求选择其他内容,服务器是否同时处理两者,或者完成它收到的第一个请求,然后参加下一个请求?
从 这里开始
我很难理解
他们说ado.net不包含连接池机制.
1) 如果我使用的是一个datareader使用web.config文件中连接字符串的类- 它是否有/不具有轮询机制?
2)如果我的所有sql连接代码都使用web.config连接字符串,那么连接池是否会启用?或不 ?
3)什么是默认值?
我创建了一个基本的Spring 3.1 - Hibernate 4 - 在Tomcat 7上运行的Mysql 5.5 Web应用程序.我通过spring + C3PO汇集了连接.
更新:我也发布了我的代码.
My Spring应用程序上下文:
<!-- Context -->
<context:component-scan base-package="com.yl.tomcat" />
<!-- AOP -->
<aop:aspectj-autoproxy />
<!-- Properties -->
<bean id="applicationProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:applicationProperties.properties" />
</bean>
<!-- Data source -->
<!-- Have spring manage connection management along with connection pooling -->
<bean id="dataSourceGlobal" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${driverClass}" />
<property name="jdbcUrl" value="${jdbcUrl" />
<property name="user" value="${user}" />
<property name="password" value="${password}" />
<!-- C3P0 Connection pool properties -->
<property name="minPoolSize" …Run Code Online (Sandbox Code Playgroud) 如果我在空闲一段时间后启动我的应用程序,我曾经得到以下错误.(我使用Spring + Hibernate + MySQL作为DB)
ERROR [org.hibernate.util.JDBCExceptionReporter]The last packet successfully received from the server was 74,188,684 milliseconds ago.
The last packet sent successfully to the server was 74,188,685 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
org.hibernate.exception.JDBCConnectionException: could not execute query
Run Code Online (Sandbox Code Playgroud)
我在下面添加了我的servlet-context.xml解决了这个问题.
<beans:property name="validationQuery" …Run Code Online (Sandbox Code Playgroud) 我有一个问题,认为我会分解为最简单的.在LAMP堆栈上有两个应用程序,一个是PHP,另一个是Java,只做同样的事情:运行一个简单的查询:
SELECT * FROM test
Run Code Online (Sandbox Code Playgroud)
PHP执行总共需要30毫秒
Java执行总共需要 230毫秒
在本地MySQL客户端上运行的查询总共需要10-15毫秒
Java 大约每次只需要大约200毫秒来建立与数据库的连接.我知道PHP使用某种内置的连接池,因此它不需要每次都建立一个新连接,因此只需要30 ms.
在Java上可能是同样的事情吗?到目前为止,我未能实现这一目标.我尝试使用Apache Commons DBCP连接池,根本没有任何更改,仍然需要同时连接到数据库.
更新:这是一个单独的问题,我正在尝试在Java上进行连接池工作,对于那些要求代码示例的人:Java MySQL连接池不工作
(滚动到结尾以查找与此相关的可能错误.)
这个连接池似乎是正确的,至少ping是成功的,但它是如何由EJB模块实际引用的?
thufir@dur:~$
thufir@dur:~$ glassfish-4.1/glassfish/bin/asadmin
Use "exit" to exit and "help" for online help.
asadmin>
asadmin> list-jdbc-connection-pools
CLI031: Warning: Option "target" is obsolete and will be ignored.
CLI031: Warning: Option "target" is obsolete and will be ignored.
__TimerPool
DerbyPool
SamplePool
connectionPool
legacy_on_glassfish
Command list-jdbc-connection-pools executed successfully.
asadmin>
asadmin> ping-connection-pool legacy_on_glassfish
Command ping-connection-pool executed successfully.
asadmin>
asadmin> list-jdbc-resources
jdbc/sample
jdbc/__TimerPool
jdbc/__default
jdbc/local
jdbc/legacy_resource
Command list-jdbc-resources executed successfully.
asadmin>
Run Code Online (Sandbox Code Playgroud)
(我不知道如何用asadmin输出jdbc连接属性)
使用Netbeans向导,这是生成的persistence.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> …Run Code Online (Sandbox Code Playgroud) 我们在Windows Server 2008 R2上运行的Apache Tomcat 7.0.54上运行了一个JSF2.0 Web服务器.我们在运行它的机器上有2个SQL服务器,另一个托管我们的库存软件.我们网页的一部分是对要添加的PartNumbers的验证.在阅读了连接池是与SQL服务器交谈的最佳实践之后,我们创建了一个并使用它来对我们的库存软件进行一些验证.
因为我想要一种方法来检查连接池的运行状况,所以我创建了一个带有ViewScoped辅助bean的测试页面,该辅助bean验证了2个已知的好的部件号.今天是本周第二次出现错误信息"Connection is closed".由于我是新来的conenction池,似乎无法找到任何有关这方面的信息,我感到困惑的是我们没有正确设置.我刚刚重置Apache服务器,它已备份并运行.所以..为了创建我的连接池,我在应用程序的META-INF/context.xml中添加了一些代码.
<Resource type="javax.sql.DataSource"
name="jdbc/FOODB"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://Foobar\Inventory;databaseName=FooInventory;user=johnDoe;password=astrongpassword;"
/>
Run Code Online (Sandbox Code Playgroud)
我必须使用ConnectionPool的基本概念是我有一个名为SqlAccessCommand的接口.它或多或少是适配器模式.在我的测试页面中,我使用RunUnsafe方法,以便我可以显示错误消息.所以这是RunUnsafe方法.
protected static DataSource getDataSource() throws NamingException {
Context context = (Context) new InitialContext().lookup("java:/comp/env");
DataSource ds = (DataSource) context.lookup("jdbc/FOODB");
return ds;
}
public static <T> T RunUnsafe(SqlAccessCommand<T> command) throws NamingException, SQLException {
try {
DataSource ds = getDataSource();
try (Connection connection = ds.getConnection();
PreparedStatement statement = connection.prepareStatement(command.getSqlStatement())) {
command.prepareStatment(statement);
try (ResultSet rs = statement.executeQuery()) {
return command.getResults(rs);
}
}
} catch (NamingException | …Run Code Online (Sandbox Code Playgroud) 找到许多解决方案但不适合我的方案的单一解决方案.
问题:我正在研究在asp.net下构建的在线软件.从过去的几天开始,我的应用程序运行缓慢,有些时候崩溃.当我试图找到问题时,我发现连接池有连接处于休眠模式.我知道有些连接是开放的但未正确关闭.在下面我将向您展示我的DBManager文件.请查看它,并给我一些建议,可以帮助我正确打开和关闭我的连接.
注意:当用户快速使用应用程序时,会抛出连接异常.我的应用程序使用许多数据输入操作符,它们是速度类型.并一次又一次地在页面之间移动.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
/// <summary>
/// Summary description for DBManager
/// </summary>
public class DBManager
{
public static SqlConnection _connection;
public static SqlCommand _command;
public static SqlDataReader _reader;
public static SqlDataAdapter _dataAdapter;
public List<SqlParameter> Parameters = new List<SqlParameter>();
public static string _connectionString = "DefaultConnectionString";
SqlTransaction _sqlTransaction;
public DBManager()
{
// TODO: Add constructor logic here
}
public DBManager(SqlTransaction sqlTransaction = null)
{
_sqlTransaction = …Run Code Online (Sandbox Code Playgroud) 初始和最小池大小
池中的最小连接数。此值还确定首次创建池或启动应用程序服务器时放置在池中的连接数。
最大游泳池
池中的最大连接数。
根据以上两个定义,如果最小池大小为1,最大池大小为100,则:
我对这两点是正确的吗?
oracle connection database-connection connection-pooling jdbc