Failed to connect to driver2.开机后,出现一个提示:为啥内?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Failed to connect to driver2.开机后,出现一个提示:为啥内?相关的知识,希望对你有一定的参考价值。

参考技术A 控制面版的添加删除中看有没有HBClient或是很棒字样的程序,把它卸载,或者打开HBClient文件夹看有没自卸载程序双击卸载,然后删除这个文件夹,再用清理软件清理一下注册表,重新启动计算机。

android 中Network error IOException: failed to connect to /127.0.0.1 (port 1433): connect failed: ECO

下面对android中出现的Network error IOException: failed to connect to /127.0.0.1 (port 1433): 做一下总结:

当用android程序调用本地的sqlserver的时候,当连接ip写成127.0.0.1的时候,怎么都连不通,出现以下的错误信息:

感觉好像是代码有问题或者是清单文件中某个权限忘加了,其实不是这样的。原来模拟器默认把127.0.0.1和localhost当做本身了,在模拟器上可以用10.0.2.2代替127.0.0.1和localhost,另外如果是在局域网环境可以用 192.168.0.x或者192.168.1.x(根据具体配置)连接本机,这样应该就不会报错了。

 

package com.example.zhouy.mytest01;

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

/**
 * Created by Administrator on 2017/12/14.
 */

public class DBUtil {
    private static Connection getSQLConnection(String ip,String user,String pwd,String db)
    {
        Connection con =null;
        try {
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:jtds:sqlserver://"+ip+":1433/"+db+";charset=utf-8",user,pwd);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return con;

    }

    public static String QuerySQL(){

        String result="";

        try {
            Connection conn = getSQLConnection("192.168.1.101","yonghuming","mima","SHUJUKU");
            String sql = "select top 10 * from users";
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next())
            {
                String s1 = rs.getString("USRNAM");
                String s2 = rs.getString("FULLNAME");
                result += s1+" - " + s2 + "\\n";
                System.out.println(s1+" - "+s2);
            }
            rs.close();
            stmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
            result += "查询数据异常!"+e.getMessage();
        }
        return result;
    }

    public static void main(String[] args){
        QuerySQL();

    }
}

 

以上是关于Failed to connect to driver2.开机后,出现一个提示:为啥内?的主要内容,如果未能解决你的问题,请参考以下文章

GlideException: Failed to load resource……java.net.SocketTimeoutException(failed to connect to xxx)

start: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart:

Failed to connect to raw.githubusercontent.com

android 中Network error IOException: failed to connect to /127.0.0.1 (port 1433): connect failed: ECO

git使用Failed to connect to 127.0.0.1 port 1080: Connection refused

failed to connect to gitee.com port 443: timed out