使用JDBC驱动程序通过代理连接到MySQL [英] Connect to MySQL using JDBC driver through a proxy

查看:232
本文介绍了使用JDBC驱动程序通过代理连接到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,我想从位于http代理后面的客户端计算机连接到Web服务器上的MySQL服务器。我已经阅读了一些解决方案,有些人认为http隧道可能有用,有些人建议使用非常旧的链接已不再可用。所以问题是:

In Java, I would like to make a connection to a MySQL server which is on the web from a client computer that is behind a http proxy. I have read few solutions some say http tunnelling might work and some suggest a very old link from oracle which is not available anymore. So the question is:

我们如何从http代理后面的计算机连接到MySQL服务器?

How can we connect to a MySQL server from a computer which is behind a http proxy?

推荐答案

您可以尝试以下代码并查看它是否有效。它通过TCP为我工作

You can try the following code and see if it works. It worked for me over TCP

package indika.jdbc.connectivity;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class ConnectOverProxy {
    public static void main(String[] args) {
        new ConnectOverProxy();
    }

    public ConnectOverProxy() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = null;
            Properties info = new Properties();
            //info.put("proxy_type", "4"); // SSL Tunneling
            info.put("proxy_host", "[proxy host]");
            info.put("proxy_port", "[proxy port]");
            info.put("proxy_user", "[proxy user]");
            info.put("proxy_password", "[proxy password]");
            info.put("user", "[db user]");
            info.put("password", "[db pass word]");
            conn = DriverManager.getConnection("jdbc:mysql://[db host]/",info);


            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("Select NOW()");
            rs.next();
            System.out.println("Data- " + rs.getString(1));
            rs.close();
            stmt.close();
            conn.close();

        } catch (SQLException er) {
            er.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}

另外看在 http://www.idssoftware.com/jdbchttps.html ,但我还没有亲自使用这个。

Also look at "http://www.idssoftware.com/jdbchttps.html", However I have not used this personally.

这篇关于使用JDBC驱动程序通过代理连接到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆