Java 无法连接到 SOCKS 代理:连接被拒绝:连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22890243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't connect to SOCKS proxy:Connection refused: connect
提问by Vamshi
I'm getting the following error. Check many solutions but didn't get the result.
我收到以下错误。检查了许多解决方案,但没有得到结果。
Not Connected to the database - networkcoding com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure ERROR: java.lang.NullPointerException The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
The following is the database connection code.
以下是数据库连接代码。
public class DBConnect {
// System.out.println("MySQL Connect Example.");
public static Connection getConnection() {
Connection conn = null;
String url = "jdbc:mysql://127.0.0.1:3306/";
String dbName = "networkcoding";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "xampp123";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url + dbName, userName, password);
System.out.println("Connected to the database "+dbName);
//conn.close();
//System.out.println("Disconnected from database");
} catch (Exception e) {
System.out.println("Not Connected to the database - "+dbName);
e.printStackTrace();
}
return conn;
}
public static void main(String arg[]){
DBConnect.getConnection();
}
}
The error is within the following part of the code:
错误在代码的以下部分:
package privacysensor;
import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import javax.swing.JOptionPane;
public class Sensors extends javax.swing.JFrame {
/**
* Creates new form Sensors
*/
String s1 = "", s2 = "", s3 = "", s4 = "", s5 = "", s6 = "", s7 = "", s8 = "", s9 = "";
DBConnect c = new DBConnect();
DateFormat df = new SimpleDateFormat("hh:mm a");
Calendar cal1 = Calendar.getInstance();
org.jdesktop.application.ResourceMap resourceMap =
org.jdesktop.application.Application.getInstance(
privacysensor.PrivacySensorApp.class).getContext().getResourceMap(Sensors.class);
Class1 x = new Class1();
int id, id1;
public Sensors() {
initComponents();
try {
id = x.idgeneration();
id1 = x.Tidgeneration();
Connection c1 = c.getConnection();
Connection c2 = c.getConnection();
PreparedStatement pst = c1.prepareStatement("update sensors set status='Offline' where id=" + id);
int s = pst.executeUpdate();
if (s == 0) {
System.out.println("Not updated");
} else {
System.out.println("Updated");
}
PreparedStatement pst1 = c2.prepareStatement("update timing set status='Offline' where id=" + id1);
s = pst1.executeUpdate();
if (s == 0) {
System.out.println("Timer updated");
} else {
System.out.println("TImer not updated");
}
} catch (Exception e) {
System.out.println(e);
}
... // End of variables declaration
}
}
Any suggestions are welcome. Thank you,
欢迎任何建议。谢谢,
采纳答案by Vamshi
In the stack trace, I got the error Can't connect to SOCKS proxy:Connection refused: connectI figured it was because of the system proxy settings, the connection was refused. Remove the proxy and it will work like a charm. To remove proxy settings in Windows 10, Open Settings- Click Network & Internet- Click ProxyIn Manual Proxy Setup, uncheckUse a proxy server
在堆栈跟踪中,我收到错误无法连接到 SOCKS 代理:连接被拒绝:连接我认为这是因为系统代理设置,连接被拒绝。删除代理,它将像魅力一样工作。要删除 Windows 10 中的代理设置,请 打开设置-单击网络和 Internet-单击手动代理设置中的代理,取消选中使用代理服务器
Thank you all.
谢谢你们。
回答by MiaSanMia
I use mac OS X and I got the error:Can't connect to SOCKS proxy:Connection refused: connect
.
I opened:
System Preferences -> Network -> Advanced ->Proxy -> unchecked SOCKS proxy
我使用 mac OS X,但出现错误:Can't connect to SOCKS proxy:Connection refused: connect
.
我打开:
系统偏好设置 -> 网络 -> 高级 -> 代理 -> 未选中的 SOCKS 代理
This resolved the problem.
这解决了问题。