源代码如下,
<%@ page import ="java.io.*"%>
<%@ page import ="java.util.*"%>
<%@ page import ="java.sql.*"%> <%
String dbUrl="jdbc:mysql://localhost:3306/bookstore?useUnicode=true&characterEncoding=GB2312";
String dbUser="root";
String dbPwd="6965050";
String driverName="com.mysql.jdbc.Driver"; Connection con=null;
Statement stmt=null;
ResultSet rs=null; Class.forName(driverName); con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
if(con!=null)
System.out.println("connect successfully!"); %>
错误页面
root cause javax.servlet.ServletException: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.ConnectException
MESSAGE: Connection refused: connect STACKTRACE: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:518)
at java.net.Socket.connect(Socket.java:468)
at java.net.Socket. <init>(Socket.java:365)
at java.net.Socket. <init>(Socket.java:208) 后面还有一大堆错误我的环境变量什么都没有设置错误,具体我的错误和我的软件版本和环境变量可以看这个贴http://topic.csdn.net/u/20090413/18/a50872d9-7ab7-4dd0-b547-a1eb83deaaab.html我的操作系统是!!!!!VISTA!!!!!!! 一直出现Connection refused: connect 错误,,,,,
当我把原代码中 localhost换成127.0.0.1,,,,,,奇迹出现了,竟然能访问数据库了,,,,,,,希望高手说明这时啥原因,,,这也太雷人了吧,,,不这样试下,岂不是要冤死。是VISTA的原因???希望有高手能发个新帖把原因什么解释下,免得再有像我这样的倒霉小白走这样的弯路
<%@ page import ="java.io.*"%>
<%@ page import ="java.util.*"%>
<%@ page import ="java.sql.*"%> <%
String dbUrl="jdbc:mysql://localhost:3306/bookstore?useUnicode=true&characterEncoding=GB2312";
String dbUser="root";
String dbPwd="6965050";
String driverName="com.mysql.jdbc.Driver"; Connection con=null;
Statement stmt=null;
ResultSet rs=null; Class.forName(driverName); con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
if(con!=null)
System.out.println("connect successfully!"); %>
错误页面
root cause javax.servlet.ServletException: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.ConnectException
MESSAGE: Connection refused: connect STACKTRACE: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:518)
at java.net.Socket.connect(Socket.java:468)
at java.net.Socket. <init>(Socket.java:365)
at java.net.Socket. <init>(Socket.java:208) 后面还有一大堆错误我的环境变量什么都没有设置错误,具体我的错误和我的软件版本和环境变量可以看这个贴http://topic.csdn.net/u/20090413/18/a50872d9-7ab7-4dd0-b547-a1eb83deaaab.html我的操作系统是!!!!!VISTA!!!!!!! 一直出现Connection refused: connect 错误,,,,,
当我把原代码中 localhost换成127.0.0.1,,,,,,奇迹出现了,竟然能访问数据库了,,,,,,,希望高手说明这时啥原因,,,这也太雷人了吧,,,不这样试下,岂不是要冤死。是VISTA的原因???希望有高手能发个新帖把原因什么解释下,免得再有像我这样的倒霉小白走这样的弯路
或者换台电脑试下吧。
#
# this is a sample hosts file used by microsoft tcp/ip for windows.
#
# this file contains the mappings of ip addresses to host names. each
# entry should be kept on an individual line. the ip address should
# be placed in the first column followed by the corresponding host name.
# the ip address and the host name should be separated by at least one
# space.
#
# additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# for example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
::1 localhost我直接在localhost后面加127.0.0.1 系统不让我保存,说权限不够,但是我已经是管理员权限了,
我想如果加上了应该能解决这个问题了
cmd
net start mysql