您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Java >> tomcat配置连接池连接mysql数据库

tomcat配置连接池连接mysql数据库

来源:网络整理     时间:2016/8/13 7:40:58     关键词:

关于网友提出的“ tomcat配置连接池连接mysql数据库”问题疑问,本网通过在网上对“ tomcat配置连接池连接mysql数据库”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: tomcat配置连接池连接mysql数据库
描述:

环境:win2000+tomcat+mysql5.0+mysql-connector-java-5.1.6-bin.jar
错误:09:44:05,717 ERROR JDBCExceptionReporter:72 - Cannot create PoolableConnectionFactory (Io 异常: The Network Adapter could not establish the connection)
请问以上问题最有可能出现在什么地方,,以一种什么方式解决,我已将所有防火墙关闭,效果也是一样,高手都看奥运去了吗?
server.xml文件配置




type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
username="amis" password="amis" maxIdle="10"
url="jdbc:mysql://127.0.0.1:3306/amis" maxActive="20" maxWait="5000"
removeAband>

<>
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

jdbc/amis
javax.sql.DataSource
Container

  
    index.jsp
  



3) 测试类PoolTest.java


package test;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.sql.ResultSet;
import javax.sql.DataSource;
public class PoolTest {
    public static Connection getConnection() throws Exception {
        Connection conn = null;
        DataSource dataSource = null;
        try {
            if (dataSource != null) {
                conn = dataSource.getConnection();
            } else {
                Context initCtx = new InitialContext();
                dataSource = (DataSource) initCtx
                        .lookup("java:/comp/env/jdbc/amis");
                conn = dataSource.getConnection();
            }
        } catch (SQLException e) {
            throw new Exception(e.getMessage());
        } catch (NamingException e) {
            throw new Exception(e.getMessage());
        }
        return conn;
    }
    public String doSomething() {
        try {
            Connection conn = getConnection();
//            PreparedStatement pstmt = conn.prepareStatement("show tables");
//            ResultSet rst = pstmt.executeQuery();
//            while(rst.next()){
//                System.out.println(rst.getString(1));
//            }
            return "ok";
        } catch (Exception e) {
            e.printStackTrace();
            return "failed with errors: " + e.getMessage();
        }
    }
}

4) 测试jsp文件

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="test.*" %>


    
test pool page
 

<%=  new PoolTest().doSomething() %>



[img=http://img7.uploadhouse.com/fileuploads/2202/22026971439f05d9ed30bf9a6235c52ffa9ebb2.jpg]pic[/img]

解决方案5:

物理连接建立错误,
检查你的数据库启动起来没?
最好检查一下服务器的的端口,看看3306端口是不是被别的应用程序占用了


以上介绍了“ tomcat配置连接池连接mysql数据库”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3247745.html

相关图片

相关文章