java.net.ConnectException:连接超时:使用路由器连接

时间:2014-07-16 07:00:41

标签: java mysql database processing router

我正在尝试将一台PC(与XAMPP)连接到另一台PC(带处理)。为此,我下载了一个用于处理的MySQL库: import de.bezier.data.sql。*;

当我使用localhost作为服务器时,它可以工作,当它们都有互联网时,它可以与其他计算机一起使用。但是,我需要这个在本地网络中工作,所以没有互联网,只有路由器的无线连接。在这里它失败了。我不知道为什么。即使我使用LAN电缆,我也可以通过URL访问“服务器”。但是当我想在Processing中访问它时,我得到了这个:

SQL.connect(): Could not connect to the database ( jdbc:mysql://192.168.0.103/event ).

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

** BEGIN NESTED EXCEPTION ** 

java.net.SocketException
MESSAGE: java.net.ConnectException: Connection timed out: connect

STACKTRACE:

java.net.SocketException: java.net.ConnectException: Connection timed out: connect
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2569)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at de.bezier.data.sql.SQL.connect(Unknown Source)
    at MySQL_example1.setup(MySQL_example1.java:56)
    at processing.core.PApplet.handleDraw(PApplet.java:2103)
    at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:190)
    at processing.core.PApplet.run(PApplet.java:2006)
    at java.lang.Thread.run(Thread.java:662)


** END NESTED EXCEPTION **



Last packet sent to the server was 26 ms ago.
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2643)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at de.bezier.data.sql.SQL.connect(Unknown Source)
    at MySQL_example1.setup(MySQL_example1.java:56)
    at processing.core.PApplet.handleDraw(PApplet.java:2103)
    at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:190)
    at processing.core.PApplet.run(PApplet.java:2006)
    at java.lang.Thread.run(Thread.java:662)

我如何让它工作?任何形式的帮助表示赞赏!

编辑:代码基本上是库中的示例。我更改了密码,用户名和我要与之通信的IP地址。 'event'是数据库,'db_name'是表。

    import de.bezier.data.sql.*;


// created 2005-05-10 by fjenett
// updated fjenett 20081129


MySQL msql;


void setup()
{
    size( 100, 100 );

    // this example assumes that you are running the 
    // mysql server locally (on "localhost").
    //

    // replace --username--, --password-- with your mysql-account.
    //
    String user     = "user123";
    String pass     = "1234";

    // name of the database to use
    //
    String database = "event";
    // add additional parameters like this:
    // bildwelt?useUnicode=true&characterEncoding=UTF-8

    // connect to database of server "localhost"
    //
    msql = new MySQL( this, "192.168.0.103", database, user, pass );

    if ( msql.connect() )
    {
        msql.query( "SELECT COUNT(*) FROM db_name" );
        msql.next();
        int rand = int(random(msql.getInt(1)));

        println( "randomrow: " + msql.getInt(1) );
    }
    else
    {
        // connection failed !
    }
}

void draw()
{
    // i know this is not really a visual sketch ...
}

EDIT2:可能是带有XAMPP的PC必须首先激活Telnet服务器服务吗?

1 个答案:

答案 0 :(得分:0)

好的,对于将来遇到同样问题的每个人:拥有XAMPP的计算机可能给了我MySQL数据库的所有权利,但计算机本身并不允许访问任何其他计算机。它只是一个临时解决方案,但是我使用XAMPP打开了计算机上的Windows防火墙并且它运行良好。