站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2SE 专题mysql数据库连接不上?

mysql数据库连接不上?

摘要: mysql数据库连接不上?


private String sDBDriver = -#34;org.gjt.mm.mysql.Driver
private String sConnStr = -#34;jdbc:mysql://localhost:3306/mytest?user=root-#38;password=system-#34;;
Class.forName(sDBDriver);
conn=DriverManager.getConnection(sConnStr);

提示错误:
java.lang.NullPointerException
at newsgroup.MysqlConnect.main(MysqlConnect.java:146)
DBConnect():Communication failure during handshake. Is there a server running on localhost:3306?
Exception in thread -#34;main-#34;

我用mysql的客户端连接数据正常。
但是查一下,3306的端口绑定的IP是0.0.0.0,这是为什么,如何解决?




mysql 的端口是 3306 吗,好像是端口错啦


你的MySQL服务器地址没设定还是没有设正确?


[client]

port=3306

[mysql]

default-character-set=gbk


# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]

# The TCP/IP Port the MySQL Server will listen on
port=3306

如果是默认设置,3306端口是没错的。


-#34;jdbc:mysql://localhost:3306/mytest?user=root-#38;password=system-#34;;

//localhost --〉替换为ip 地址 或者 127.0.0.1


找不到服务器啊


搞定了,我把mysql的驱动升到5.0就好使了。


↑返回目录
前一篇: 字符串数组的比较???compareTo()的问题
后一篇: 打印1到100的数