简体   繁体   中英

Connecting Java to MySQL through that requires proxy, username and password

I am working on a desktop application that connects to a MySQL database in a godaddy.com server.

Everything is working fine, except when working from a network that requires a proxy, username and a password

Do I need to set the proxy from the code? How?
Or is there away around?

Here is my database connection code:

url = "jdbc:mysql://XXXXX.db.XXXXX.hostedresource.com/";
dbName = "XXXXXX";
driver = "com.mysql.jdbc.Driver";
unicode = "?useUnicode=yes&characterEncoding=UTF-8";
try{
    Class.forName(driver);
    connection = DriverManager.getConnection(url+dbName+unicode, "XXXXX", "XXXXX");
}catch (Exception e) {javax.swing.JOptionPane.showMessageDialog(null, e);}

The first step would be to make sure the java runtime is able to access the Internet through your proxy, and to do that see how to setup proxy for java .

You should also set up the HTTP_PROXY environment variable for your shell. Syntax is

HTTP_PROXY = http://username@password:proxy.server.com:8080/

However, note that (at least for Windows), if you add the above to your system variables, they will only take effect on the next reboot and you need admin rights to modify system variables. You can add it to your user variables and they will take effect on next login (or next invocation of the command prompt).

HTTP proxies will not forward your JDBC (in this case MySQL) at all.

You can setup HTTPS CONNECT proxy with SSH tunneling, but this is different story.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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