简体   繁体   English

与Sourceforge的mysql数据库的JDBC连接

[英]JDBC connection to sourceforge's mysql database

How do you specify that the JDBC connection to mysql in the typical line 如何在典型行中指定到mysql的JDBC连接

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

I requested the remote access from sourceforge but using the given port 4040 i no able to connect to it. 我请求从sourceforge进行远程访问,但是使用给定的端口4040无法连接到它。

Here is the error: 这是错误:

    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.

the URL syntax is given here: URL语法在此处给出:

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

I think you have another issue. 我认为您还有另一个问题。

The default port for MySQL is 3306. I'm not sure where you got that port number, or the username and password you're using, but that message suggests to me that you were able to make the connection but MySQL refused you access. MySQL的默认端口是3306。我不确定您从何处获得该端口号或使用的用户名和密码,但是该消息向我提示您能够建立连接,但MySQL拒绝了您的访问。

MySQL GRANTs permissions for access from a particular IP address. MySQL GRANTs允许从特定IP地址进行访问的权限。 I can't imagine that source forge has asked for your IP address, so I'm guessing that your access should be anonymous and read-only. 我无法想象源伪造会要求您提供IP地址,因此我猜测您的访问权限应为匿名且只读。

I don't see anything in the stack trace that implies that your request is making it to the remote server, so I think you're having a firewall issue of some sort. 我在堆栈跟踪中没有看到任何暗示您的请求正在发送到远程服务器的内容,因此我认为您遇到了某种防火墙问题。 Try using telnet to see if you're making a connection: telnet mysql-o.sourceforge.net 4040 You'll get some text from the server if the network is letting you through. 尝试使用telnet来查看是否建立连接: telnet mysql-o.sourceforge.net 4040如果网络允许您通过服务器,您将获得一些文本。 3306 is the usual port for MySQL so you might want to try that too. 3306是MySQL的常用端口,因此您可能也想尝试一下。 You'll need to solve this part first, then whatever permission issues follow. 您首先需要解决这一部分,然后再解决任何权限问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM