急 jsp连接数据库mysql出现错误了
网页代码:
<%@ page language="java" %>
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>JDBC</title>
</head>
<body>
<h1>Connect MySQL</h1>
<table border=1>
<tr>
<td>公司名</td>
<td>公司ID</td>
</tr>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/cycle?user=root&password=");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from Users");
while(rs.next()){
%>
<tr>
<td><%=rs.getString("companyname")%></td>
<td><%=rs.getString("companyID")%></td>
</tr>
<%
}
rs.close();
con.close();
%>
</table>
</body>
</html>
出错:
javax.servlet.ServletException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.lang.NumberFormatException)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:673)
org.apache.jsp.myweb.fristtest_jsp._jspService(fristtest_jsp.java:90)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause
java.sql.SQLException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.lang.NumberFormatException)
com.mysql.jdbc.Connection.connectionInit(Unknown Source)
com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
com.mysql.jdbc.Driver.connect(Unknown Source)
java.sql.DriverManager.getConnection(DriverManager.java:512)
java.sql.DriverManager.getConnection(DriverManager.java:193)
org.apache.jsp.myweb.fristtest_jsp._jspService(fristtest_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.