求解决java中用jdbc方式连接mysql数据库的问题,错误异常如下:(解决后再加分)
Communicationslinkfailureduetounderlyingexception:**BEGINNESTEDEXCEPTION**com.mysql.j...
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());
}
}
} 展开
** 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());
}
}
} 展开
展开全部
你这个语句什么都没做,报这个异常是不是数据库连接超时了啊。还有你追问的图不是MYSQL貌似是SQL server 。想用MYSQL建议你下载并安装MYSQL
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
就是你使用的是 SQLserver数据库,但是数据库连接是 mysql的 dbc:mysql://192.168.223.54:1433/saleSystem
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我了个去,你起的是SQLServer,为啥你用MYSQL包连接呢????
更多追问追答
追问
菜鸟我不懂,求解释
追答
你给1楼的图片中我看你起的是微软的SQLServer2000
根本不是MYSQL数据库
根本不是一个概念
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
mysql服务没起来哦。
更多追问追答
追问
这样不是表示mysql服务已启动了吗?
追答
哥,你不是说是mysql吗,怎么给了sql server的服务图片
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
mysql配置成功了么?
把代码贴出来看看
把代码贴出来看看
追问
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();
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询