Android远程JDBC连接

时间:2016-03-10 15:43:04

标签: android jdbc pervasive

我正在尝试在我的文件服务器上查询Pervasive数据库,该数据库与其他几台计算机在网络上。在路由器上,我设置了适当的端口以转发到运行PSQL引擎的文件服务器。

enter image description here

通过visitng ip4.me,我得到了路由器的IP地址。

这是代码:

class Task implements Runnable {
    public void run() {

        String routerIP ="*.*.*.*"; //blanked it out for privacy reasons

        //String url = "jdbc:pervasive://192.168.1.139:1583/DB";  // THIS WORKS LOCALLY 
        String url = "jdbc:pervasive://" + routerIP + ":1583/DB";  //this throws exception
    String query = "select NAME from CUSTOMER";
    Statement stmt;
    try {
        Class.forName("com.pervasive.jdbc.v2.Driver");
    } catch (Exception e) {
        Log.d("ClassNotFoundException:", e.toString());
        toast1.show();
    }
    try {
        Connection conn = DriverManager.getConnection(url, "username", "password");
        stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        ResultSetMetaData rsmd = rs.getMetaData();
        int numberOfColumns = rsmd.getColumnCount();

        int i = 1;
        while (rs.next()) {
            for (i = 1; i <= numberOfColumns; i++) {
                Log.d("Data", rs.getString(i));
                myStringArray1.add(rs.getString(i));
            }
        }

        stmt.close();
        conn.close();

    } catch (SQLException ex) {
        Log.d("Error", ex.toString());
        toast2.show();
    }
}
}

正在发生一些不同的事情。当我尝试连接本地wifi(与文件服务器相同的网络)时,我得到java.sql.SQLException: java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

尝试使用4G连接(我打算使用),我明白了 java.net.ConnectException: failed to connect to /*.*.*.* (port 1583): connect failed: ETIMEDOUT (Connection timed out)

(再次,出于隐私原因,我将ip清空了)

0 个答案:

没有答案