【发布时间】:2015-03-28 09:15:33
【问题描述】:
我可以从 Eclipse 数据源资源管理器连接到 MySQL 数据库(ping 成功),但是从 Eclipse 在 Tomcat 服务器中运行以下代码不会连接到数据库。我收到“无法连接..”消息。
<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:8889/LenderDetails", "root", "root");
out.println("connection ="+connection.toString());
if(!connection.isClosed())
%>
<%
out.println("Successfully connected to " + "MySQL server using TCP/IP...");
connection.close();
}
catch(Exception ex){
%>
<%
out.println("Unable to connect to database.");
}
%>
JSP 代码中的 URL 与 DataSourceExplorer 中的 URL 完全相同。
Eclipse Luna (4.4.2)、Tomcat V7.0、mysql-connenctor-java-5.1.24-bin.jar、Java SE 7。
任何想法为什么我无法从 JSP 连接或在哪里可以找到更多详细信息(Tomcat 日志)?
【问题讨论】: