Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
com.mysql.jdbc.CommunicationsException
MESSAGE: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: Connection reset
STACKTRACE:
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1994)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:573)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1044)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at wahack.visable.jdbcQuery.ConnectionODBC(jdbcQuery.java:20)
at wahack.visable.jdbcQuery.main(jdbcQuery.java:12)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
STACKTRACE:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: Connection reset
STACKTRACE:
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1994)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:573)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1044)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at wahack.visable.jdbcQuery.ConnectionODBC(jdbcQuery.java:20)
at wahack.visable.jdbcQuery.main(jdbcQuery.java:12)
** END NESTED EXCEPTION **
代码:import java.sql.*;
public class jdbcQuery
{
public static void main(String[] args)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://192.168.223.54:1433/saleSystem","sa","password");
con.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
菜鸟我不懂,求解释
追答你给1楼的图片中我看你起的是微软的SQLServer2000
根本不是MYSQL数据库
根本不是一个概念
怎么解决?我刚学数据库,要启用mysql数据库?
追答你直接连SQLServer得了
http://zhidao.baidu.com/question/79643275.html?an=0&si=7
去下SQLServer的驱动
照着上面的连
这样不是表示mysql服务已启动了吗?
追答哥,你不是说是mysql吗,怎么给了sql server的服务图片
追问是我搞错了。已解决,谢谢
mysql服务、TCP/IP协议已启动,还要怎么配置?代码在问题补充里
追答监听接口打开了吗?如果数据库没监听也不行
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectJDBC {
public static final String DBDRIVER = "org.gjt.mm.mysql.Driver";//驱动jar包
public static final String DBURL = "jdbc:mysql://localhost:3306/DatabaseName";//数据库地址及DatabaseName名称
public static final String DBUSER = "root";//数据库账号
public static final String DBPASS = "mysqladmin";//数据库密码
private Connection conn = null;
public Connection getConn() {
try {
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}
public void closeConn() {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
这就是一个连接数据库的,自己先测试一下 如果没有报错,就说明连接成功了
我晕,楼主的是SQL Server的嘛,你怎么说是mysql = =!
SQL Server 和mysql完全不是同一个 我在给你一个连接SQL Server的
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectJDBC {
public static final String DBDRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver";//驱动jar包
public static final String DBURL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=";//数据库地址及DatabaseName名称
public static final String DBUSER = "sa";//数据库账号
public static final String DBPASS = "";//数据库密码
private Connection conn = null;
public Connection getConn() {
try {
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}
public void closeConn() {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}