无法连接到SOCKS代理:连接被拒绝:连接

4
我遇到了以下错误。查看了很多解决方案,但没有得到结果。
未连接到数据库 - networkcoding
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 通信链接失败
错误:java.lang.NullPointerException
最后一个数据包成功发送到服务器的时间为0毫秒。
驱动程序没有从服务器收到任何数据包。
下面是数据库连接代码。
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();
    }
}

错误出现在以下代码部分:
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                   
    }
}

欢迎提出任何建议。谢谢。


https://dev59.com/InI95IYBdhLWcg3w2h56 - fdsa
你能提供完整的堆栈跟踪吗? - Warren Dew
是哪一个?连接被拒绝了吗?还是空指针异常?SOCKS代理在哪里变得更流行?问题是什么? - user207421
1
谢谢大家,我能够解决它了。我移除了代理设置。从堆栈跟踪中了解到无法连接到SOCKS代理:连接被拒绝。 - Vamshi
1
你的问题中除了奇怪的标题外,没有提到任何关于SOCKS代理的内容。不清楚你在问什么。 - user207421
2个回答

10
我使用Mac OS X时遇到了错误:
无法连接到SOCKS代理:连接被拒绝
我打开了如下菜单:
系统偏好设置 -> 网络 -> 高级 -> 代理 -> 取消勾选SOCKS代理。
这个操作解决了问题。

-2
在堆栈跟踪中,我遇到了错误无法连接到SOCKS代理:拒绝连接。我想这是因为系统代理设置导致的连接被拒绝。删除代理,它就会像魔术般地工作。要在Windows 10中删除代理设置, 打开设置 - 点击网络和Internet - 点击代理 在手动代理设置中,取消选中使用代理服务器

谢谢大家。


你的问题中堆栈跟踪中没有这样的错误。 - user207421

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接