我完全默认安装的mysql里面的访问权限是最大的了,所有用户都没有密码 jsp内容是: <html> <head> <title>MY First MySQL Test</title></head> <body> <%@ page language="java" import="java.sql.*" contentType="text/html;charset=gb2312" %> <% String driver="org.gjt.mm.mysql.Driver"; String url="jdbc:mysql://222.18.15.131:3306/test"; String user="root"; String password="225and223"; try {Class.forName(driver);} catch(Exception e) {out.println("无法加载驱动程序!!"+driver); e.printStackTrace();} try { Connection con=DriverManager.getConnection(url,user,password); if(!con.isClosed( )){%> <p align=center><b>数据库连接成功!</b></p> <hr> <%} Statement sqlStmt=con.createStatement (java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY); String sqlQuery="select version(), now(), database(), user()"; ResultSet sqlRst=sqlStmt.executeQuery (sqlQuery); while (sqlRst.next()) { out.println(sqlRst.getString(1)); out.println(sqlRst.getString(2)); out.println(sqlRst.getString(3)); out.println(sqlRst.getString(4)); out.println("<hr><br>"); } con.close( );} catch(SQLException ee) {out.println("数据库连接失败!"); out.println(ee); return; }%> <%="数据库连接成功"%> </body> </html>
结果出错为: 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)