2017 May 29 ~ June 4【泰國 素叻他尼 Surat Thani Thailand 🌊⛵️✈️👭】Ratchaprapa Dam, Koh Samui, Khao Sok National Park

圖片
My first trip to Surat Thani Thailand!

Ratchaprapa Dam is located in South Thailand and I highly recommend it as a destination if you are nature-loving traveller and considering traveling in Thailand.
We had wonderful two night stay at Keree Warin Resort which was a raft house accommodation on the lake. This lake is big, as I think it took around 30 minutes of travel by long tail boat to reach our resort.
We spent our time enjoying the breath-takingly beautiful views, swimming and canoeing around the vicinity of the raft house.It's really a great place to relax and have some quiet time in beautiful surrounding.


















Java Database Connectivity (JDBC) - com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying except

前陣子在處理某人丟給我要我修改的一支 Java Server Page 程式,花了一些時間安裝配置好JSP的執行環境和開發環境後,開啟網頁要測試關鍵字搜尋時卻顯示一片空白,但 Tomcat 好像無法跟 Rails 的 Mongrel Server 一樣可以從 Terminal 即時瀏覽輸出訊息,所以只好去查看/var/log/tomcat6/catalina.out記錄檔,之後找到如下的錯誤訊息:

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.ConnectException
MESSAGE: Connection refused

STACKTRACE:

java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:310)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:176)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:163)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at java.net.Socket.(Socket.java:392)
at java.net.Socket.(Socket.java:235)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:173)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:267)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2739)
at com.mysql.jdbc.Connection.(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:222)
at foo.retrieve.caluQueryM(retrieve.java:76)
at foo.retrieve.(retrieve.java:34)
at org.apache.jsp.showDocFeature_jsp._jspService(showDocFeature_jsp.java:100)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:636)


** END NESTED EXCEPTION **

從log file的輸出看來,這個錯誤明顯是Java程序没有連接上MySQL資料庫,導致無法進行任何與資料庫相關的操作。因此這個錯誤本質上是一個網路的問題。大致瀏覽了一下程式碼,發現它是採用TCP/IP的方式去連接MySQL:

String sDriver = "com.mysql.jdbc.Driver";
String sCon = "jdbc:mysql://localhost:3306/" + myprojectuser=root&password=123321&useUnicode=true&characterEncoding=big5";

最後我從Oracle論壇上面找到了一個相似的討論串,終於得到了頭緒,問題就出在MySQL設置檔裡有個選項skip-networking,而我以往習慣會將它設置為ON(因為在開發Ruby on Rails應用程式時根本不會遇到這種問題),因為這個設置,因此使得這支JSP程式無法透過TCP/IP去連接MySQL。解決方法只要將/etc/mysql/my.cnf設置檔中的skip-networking這個選項註解掉或移除就行了,同時我也將skip-name-resolve的選項給註解掉,最後重新啟動MySQL和Tomcat就搞定了!

Development Environment:Linux Ubuntu 10.04 + MySQL 5.1.46 Community Server + JDK 6.0 + MySQL Connector 5.1.6 with "com.mysql.jdbc.Driver" class + Apache2 + Tomcat6


熱門文章

[轉載] 洛克菲勒寫給兒子的38封信(全文)

September, 2012 白姑大山二天一夜~其實沒那麼累,只是路途遙遠

【清邁之旅 Part 1|Exploring Doi Suthep-Pui National Park】The 6 Day Itinerary To Explore Chiang Mai And Northern Thailand's Mountains

2013.5.25~26【新阿溪縱走】眠月線鐵道線探勘。順登松山、萬歲山、小笠原山、對高岳

2018, Sep 21【嘉義。阿里山】特富野古道健行。鐵道、迷霧、森林(Tefuye Historical Trail)

2018 May 5~6【宜蘭】南方澳漁港~豆腐岬~朝陽國家步道~南澳觀音海岸~礁溪福哥石窯雞

FbGraph + OmniAuth + Facebook Graph API on Rails application

文章列表

聯絡我

名稱

以電子郵件傳送 *

訊息 *