作者a1e (我上了贼船了囧)
看板java
标题[分享]JDBC连MySQL
时间Tue Jul 27 09:16:46 2010
最近在练习SQL语法,手上没其他资料库软体可用,只好拿mysql来用
好不容易找到mysql的jdbc
(容我抱怨一下mysql的官网,下载失败重连竟然还要你填一堆资料,然後最少三天
再把东西寄给你....)
mysql装完,classpath设完,写个测试来看看有没有连到
结果出现
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
看到这个我囧了,很明显是连不到资料库,防火墙也关掉後
还是出现这个问题
努力奋战半个小时,在mysql官网找到解答Orz
http://bugs.mysql.com/bug.php?id=47494
(最後一个回覆)
An entry has been added to the 5.1.10 changelog:
The DriverManager.getConnection() method ignored a non-standard port
if it was specifiedin the JDBC connection string. Connector/J always
used the standard port 3306 forconnection creation. For example, if
the string was jdbc:mysql://localhost:6777,Connector/J would attempt
to connect to port 3306, rather than 6777.
改设成3306一试就ok,用其他的port都是这个问题Orz
结论就是mysql的port乖乖设3306就好,不要耍帅设什麽5566、7788....etc
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.69.178.34
1F:→ tkcn:你没看清楚 mysql 官网,其实可以不用填资料 ~__~ 07/27 09:25
2F:→ a1e:不用填吗?囧 07/27 09:28
3F:推 bala045:不用= = 07/27 10:20
4F:→ jayinhoward:不用填阿 07/27 10:35
5F:推 hydrapin:XDDD 07/27 19:58
6F:→ moremore1234:mysql的资料填写是可以跳过的=.= 07/27 20:39
7F:推 puzi:之前我下载java的时候还也跑去填...後来有一天发现不用填XD 07/30 22:24
8F:推 slalala:你上了贼船了囧 08/01 21:11
9F:推 maxtsai:感谢~我也遇到这个问题 卡了一个晚上 08/12 00:22