先把你的那个Context设置粘上来让大家看看是怎么设置的。
解决方案 »
- 一个奇怪的问题
- DOM4J处理的XML~在某些人的电脑上处理中文是好的.某些人电脑上面是乱码??
- 有什么java 程序(代码或者方法)可以让Tomcat重启
- 如何在MAC下创建简单的下拉框(非默认的)
- 网上技术交流会:SOA架构中的服务中介-- ESB
- 服务器端如何判断上传Excel 小于2M的允许上传 -----------------------------救命啊。。。。。。
- 请问 tomcat 出现 ClassFormatError错误,是什么原因?
- struts有这样的插件吗?????
- tomcat5的两个版本有一个网页访问数据库的部分显示乱码,Help me?
- EJB 可不可以继承?!
- 使用weblogic操作oracle数据库游标出错
- 数据集操作
prefix="aaa_database_log." suffix=".txt"
timestamp="true"/> <Resource name="jdbc/Mysql"
auth="Container"
type="javax.sql.DataSource"/> <ResourceParams name="jdbc/Mysql">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>username</name>
<value>aaa</value>
</parameter>
<parameter>
<name>password</name>
<value>aaa</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value><![CDATA[jdbc:mysql://localhost:3306/aaa?useUnicode=true&characterEncoding=GBK]]></value>
</parameter> <parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<value>300</value>
</parameter> </ResourceParams></Context>
value>jdbc:mysql://localhost:3306/aaa?useUnicode=true&characterEncoding=GBK</value> 另外你用的那些连接用完了之后有没有关掉,另外还有三个参数,你在Tomcat\webapps\tomcat-docs下面有文档说明的。
<name>url</name>
<value>jdbc:mysql://localhost:3306/job?autoReconnect=true</value>
</parameter>
这是我自己的连接池里面那个URL那项,就是象上面那样写的,我用了好长时间也没有出问题,而且在Linux下也是这样写的。
还有就是不一定要在这个URL中指定编码,MYSQL数据库这样指定编码在你的SQL中如果有"="的时候,它可能提示说这个=附近有错误,但实际是没有错误的,这种情况我遇到好几次了,没有办法只要把那个字符集编码去掉就没有问题的。
有乱码是因为你从数据库中取出来的时候没有转换一次。只要你转换一次就可以了,往数据库里写可以不管。
另外三个参数是
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter> <parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter> <parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter> 这三个参数是说回收那些Abandoned(这个词翻译成中文一点都不好听,所以直接用英文了)的Connection,回收时间间隔,记录这个Abandoned的Connection.大至是这样的。
* Classname: DataBaseMysqlPool
* Version: 1.0
* Creation: 2004-12-09
* Update:
*
* Author: squares
* Contact: [email protected]
* Copyright: (c) 2004 www.365mx.com All rights reserved.
*
* Function:用于操作Tomcat Mysql连接池的类
*/package com.squares.bj.tools;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;/**
* 用于操作Tomcat Mysql连接池的类
* <p>
*
* @version 1.0 2004-10-07
* @author squares
*/public class DataBaseMysqlPool { private static Context context; private static DataSource dataSource; /**
* Init Connection
* <p>
*/ static { try {
context = new InitialContext();
dataSource = (DataSource) context
.lookup("java:comp/env/jdbc/Mysql"); } catch (Exception e) {
} } /**
* Result、Statement、Connection Close
* <p>
*
* @throws SQLException
*/ public void Close(ResultSet resultSets,
PreparedStatement preparedStatements, Connection connections)
throws SQLException { if (resultSets != null) {
resultSets.close();
resultSets = null;
} if (preparedStatements != null) {
preparedStatements.close();
preparedStatements = null;
} if (connections != null) {
connections.close();
connections = null;
} } /**
* Get Connection
* <p>
*
* @return Connection
* @throws SQLException
*/ public Connection GetConnection() throws SQLException { Connection connection; connection = dataSource.getConnection(); return connection; }
}
没问题啊