App下載
首頁javaconnectionJava JDBC - 如何使用JDBC驅(qū)動(dòng)程序通過代理連接到MySQL

Java JDBC - 如何使用JDBC驅(qū)動(dòng)程序通過代理連接到MySQL

我們想知道如何使用JDBC驅(qū)動(dòng)程序通過代理連接到MySQL。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class Main {
  public static void main(String[] args) throws Exception{
    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();
  }
}