tomcal中的server.xml配置数据库连接出错,请指点,谢谢
在D:\jakarta-tomcat-5.0.28\conf\server.xml中配置数据库联接
地址设为"localhost"或者"10.52.13.143"可以正常访问,但设为192.168.1.143就出错
两个IP都是局域网里的地址,为何会出现这样的错误了,请高手指教,谢谢!
-------------------------------------------------
抛出的错误:
java.lang.Exception: DBUtils内部错误:系统不能取得连接: Cannot create PoolableConnectionFactory
-------------------------------------------------
代码:
public final class DB_AHD {
private static DataSource ds = null;
static {
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource) envCtx.lookup("jdbc/ahd");
} catch (Exception e) {
System.out.println("DBUtils内部错误:系统不能装载数据源: " + e.getMessage());
}
}
public DB_AHD() {
}
public static Connection getConnection() throws Exception {
try {
Connection connection = null;
connection = ds.getConnection();
return connection;
} catch (Exception e) {
throw new Exception("DBUtils内部错误:系统不能取得连接: " + e.getMessage());
}
}
public static void closeConnection(Connection connection) throws Exception {
if (connection == null)
return;
try {
connection.close();
} catch (Exception e) {
throw new Exception("DBUtils内部错误:系统不能关闭连接: " + e.getMessage());
}
}
public static void resetStatement(Statement statement) throws Exception {
if (statement != null) {
try {
statement.setMaxRows(0);
} catch (SQLException e) {
throw new Exception(
"DBUtils内部错误:Cannot reset statement MaxRows."
+ e.getMessage());
}
try {
statement.setFetchSize(0);
} catch (SQLException sqle) {
}
}
}
public static void closeStatement(Statement statement) throws Exception {
try {
if (statement != null)
statement.close();
} catch (SQLException e) {
throw new Exception("DBUtils内部错误:Cannot close statement. "
+ e.getMessage());
}
}
public static void closeResultSet(ResultSet rs) throws Exception {
try {
if (rs != null)
rs.close();
} catch (SQLException e) {
throw new Exception("DBUtils内部错误: Cannot close resultset."
+ e.getMessage());
}
}
}
--------------------------------------------------
server.xml中的配置:
<Context path="/tProj" reloadable="true" docBase="D:\eclipse\workspace\testProj\WebRoot" workDir="D:\eclipse\workspace\testProj\work">
<!-- SQL Server for ahd -->
<Resource name="jdbc/ahd" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/ahd">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://192.168.1.143:1433;user=sa;password=123;DataBaseName=ahd</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>dhcc</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
</ResourceParams>
</Context>