2011-08-20 158 views
0

如何指定了JDBC連接到MySQL在典型的線JDBC連接sourceforge上的MySQL數據庫

DriverManager.getConnection("jdbc:mysql://mysql-o.sourceforge.net:4040/o582544_oopp", "user", "pass"); 

我要求從SourceForge遠程訪問,但使用指定的端口4040我沒有能夠連接到它。

以下是錯誤:

Driver Loaded. 
Exception in thread "main" 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. 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116) 
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344) 
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333) 
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370) 
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154) 
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792) 
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381) 
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305) 
    at java.sql.DriverManager.getConnection(DriverManager.java:582) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at TestMySQL.main(TestMySQL.java:17) 
Caused by: java.net.ConnectException: Connection refused: connect 
    at java.net.PlainSocketImpl.socketConnect(Native Method) 
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) 
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213) 
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200) 
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) 
    at java.net.Socket.connect(Socket.java:529) 
    at java.net.Socket.connect(Socket.java:478) 
    at java.net.Socket.<init>(Socket.java:375) 
    at java.net.Socket.<init>(Socket.java:218) 
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257) 
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294) 
    ... 15 more 

Process completed. 

回答

0

URL語法在這裏給出:

http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html

我認爲你有其他問題。

MySQL的默認端口是3306,我不知道你在哪裏得到了端口號,或者你正在使用的用戶名和密碼,但該消息暗示對我說,你是能夠使連接,但MySQL的拒絕你訪問。

的MySQL權限授予來自特定IP地址的訪問。我無法想象,源鍛造已要求您的IP地址,所以我猜,你的訪問應該是匿名的,只讀的。

0

我沒有看到在這意味着您的請求被它使遠程服務器堆棧跟蹤任何東西,所以我覺得你有某種形式的防火牆問題。嘗試使用telnet,看看你正在做一個連接:telnet mysql-o.sourceforge.net 4040即使你的網絡是通過讓你從服務器獲取一些文本。 3306是MySQL的常用端口,因此您可能也想嘗試一下。您需要先解決這部分問題,然後再解決任何許可問題。