mysql4.1.14、tomcat5.5、jdk5.5、linux redhat es3
错误表现:
HTTP Status 500 -
exception
javax.servlet.ServletException: Servlet execution threw an exception
root cause
java.lang.ThreadDeath
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1221)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1181)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
com.byread.DbConnection.SqlManger.getRS(SqlManger.java:48)
com.byread.action.CheckUserAction.execute(CheckUserAction.java:36)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
tomcat的server.xml中数据连接部分
win下面的:
<Context path="" docBase="D:\VSS\code\web" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/mysql" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" maxIdle="60" maxWait="500" username="root" password="pass" url="jdbc:mysql://127.0.0.1:3306/byread?autoReconnect=true&useUnicode=true&characterEncoding=gbk" maxActive="100"/>
</Context>
linux下面的:
<Context path="" docBase="/usr/web" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/mysql" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" maxIdle="60" maxWait="500" username="root" password="pass" url="jdbc:mysql://127.0.0.1:3306/byread?autoReconnect=true&useUnicode=true&characterEncoding=gbk" maxActive="100"/>
</Context>
连接数据库的基类
package com.by.DbConnection;
* <p>集中处理数据库操作
*/
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import com.by.common.Log;
public class SqlManger {
private ResultSet rs=null;
private Connection conn;
private Statement stmt;
private DataSource ds;
private Log logger=new Log();
public SqlManger()
{
//构造函数
}
/**
* <p>使用连接池根据sql语句获得Resultset并返回
* @param strSql
* @return
*/
public ResultSet getRS(String strSql)
{
conn=CommonDAO("jdbc/mysql");
try
{
//System.out.println(strSql);
logger.doWriteLog(strSql);
stmt=conn.createStatement();
rs=stmt.executeQuery(strSql);
}
catch(SQLException e)
{
logger.doWriteLog("SQLException : Exception found at SqlManger.getRS()");
logger.doWriteLog("Info : Find SQLException and release Connection");
e.printStackTrace();
close();
}
return rs;
}
public int updateDB(String strSql)
{
int ret =0;
conn=CommonDAO("jdbc/mysql");
try
{
//conn.setAutoCommit(false);// 更改JDBC事务的默认提交方式
logger.doWriteLog(strSql);
stmt=conn.createStatement();
ret=stmt.executeUpdate(strSql);
}
catch(SQLException e)
{
logger.doWriteLog("SQLException : Exception found at SqlManger.getRS()");
logger.doWriteLog("Info : Find SQLException and release Connection");
e.printStackTrace();
}
finally
{
close();
}
return ret;
}
public int updateDB(String strSqla,String strSqlb,String strSqlc,String strSqld)
{
int ret =0;
conn=CommonDAO("jdbc/mysql");
try
{
conn.setAutoCommit(false);// 更改JDBC事务的默认提交方式
stmt=conn.createStatement();
if(!strSqla.equals(""))
{
logger.doWriteLog(strSqla);
ret=stmt.executeUpdate(strSqla);
}
if(!strSqlb.equals(""))
{
logger.doWriteLog(strSqlb);
ret=stmt.executeUpdate(strSqlb);
}
if(!strSqlc.equals(""))
{
logger.doWriteLog(strSqlc);
ret=stmt.executeUpdate(strSqlc);
}
if(!strSqld.equals(""))
{
logger.doWriteLog(strSqld);
ret=stmt.executeUpdate(strSqld);
}
conn.commit();//提交JDBC事务
conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式
}
catch(Exception e)
{
ret=0;
//回滚JDBC事务
try
{
conn.rollback();
}
catch(SQLException ex)
{
ex.printStackTrace();
}
logger.doWriteLog("SQLException : Exception found at SqlManger.getRS()");
logger.doWriteLog("Info : Find SQLException and release Connection");
e.printStackTrace();
}
finally
{
close();
}
System.out.println("ret---------------------"+ret);
return ret;
}
public synchronized Connection CommonDAO(String jndiDataSource) {
try {
Context env = new InitialContext();
ds = (DataSource) env.lookup("java:comp/env/" + jndiDataSource);
conn = ds.getConnection();
} catch (Exception ex) {
ex.printStackTrace();
}
return conn;
}
public synchronized void close() {
try {
if(null!=stmt)stmt.close();
stmt=null;
if(null!=conn)conn.close();
conn=null;
} catch (Exception ex) {
stmt=null;
conn=null;
ex.printStackTrace();
}
}
}
这个连接在windows下面测试了很久都没有问题,今天整合到linux上面就是连接不上。
万分紧急请各位大侠救助啊!
--转自