[分享]JDBC連MySQL
最近在練習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
→
07/27 09:25, , 1F
07/27 09:25, 1F
→
07/27 09:28, , 2F
07/27 09:28, 2F
推
07/27 10:20, , 3F
07/27 10:20, 3F
→
07/27 10:35, , 4F
07/27 10:35, 4F
推
07/27 19:58, , 5F
07/27 19:58, 5F
→
07/27 20:39, , 6F
07/27 20:39, 6F
推
07/30 22:24, , 7F
07/30 22:24, 7F
推
08/01 21:11, , 8F
08/01 21:11, 8F
推
08/12 00:22, , 9F
08/12 00:22, 9F