当前位置:编程学习 > JAVA >>

mysql&tomcat配置数据源以后无法访问mysql数据库,而且还不报错,跪求支援

数据源tomcat配置信息:

server.xml
<Context path="/NDP950_Server" docBase="NDP950_Server"
                 debug="5" reloadable="true" crossContext="true">
             <Resource 
                name="jdbc/NDP950_Server" 
                auth="Container" 
                type="javax.sql.DataSource" 
                maxActive="100" 
                maxldle="30" 
                maxWait="10000" 
                username="root" 
                password="neolinkota" 
                driverClassName="com.mysql.jdbc.Driver" 
                url="jdbc:mysql://localhost:3306/ndp950db?autoReconnect=true"/>
        </Context>
      </Host>

/apache-tomcat-7.0.42/webapps/NDP950_Server/WEB-INF/web.xml
<description>MySql App</description>
  <resource-ref>
     <description>DB Connection</description>
     <res-ref-name>jdbc/NDP950_Server</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
  </resource-ref>

在/apache-tomcat-7.0.42/webapps/common中导入jar包

前台测试代码.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.sql.*" %>
    <title>My JSP 'index.jsp' starting page</title>
  </head>
  <body>
        <%
            Connection conn=null;
            Statement stmt=null;
            ResultSet rs=null;
            try
            {
                Context ctx=new InitialContext();

                DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/NDP950_Server");    
                conn=ds.getConnection();
 conn=ds.getConnection();

                stmt=conn.createStatement();
                String sql="select * from Admin_inforsdada";
                rs=stmt.executeQuery(sql);
                while(rs.next())
                {
                        out.print(rs.getString(1)+" "+"dsada");
                        out.print(rs.getString(2)+"<br/>");
                }
            }catch(Exception e)
            {
                        out.print("error");
                e.printStackTrace();
            }
        %>
 <%
                try
                {
                        conn.close();
                }catch(Exception e)
                {
                        e.printStackTrace();
                }
        %>
</body>
</html>

当测试文件被访问的时候,程序执行到conn=ds.getConnection();的时候抛出异常,不知到为什么?跪求大侠给点指点和方向。

--------------------编程问答-------------------- 出现什么异常? --------------------编程问答-------------------- 我也不知道,只是页面显示了error,我查看了tomcat的log,没有异常信息。 --------------------编程问答-------------------- 你搞个error.jsp文件,里面写上<s:debug/>标签,这样应该可以看到报错 --------------------编程问答-------------------- 把防火墙关掉 --------------------编程问答-------------------- 在debug模式调试
补充:Java ,  Web 开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,