Java+Android连不上sqlserver2012 5C

package com.example.talent;
import java.sql.*;
import com.microsoft.sqlserver.jdbc.SQLServerDriver;
import java.lang.*;
import android.R.string;
public class db {
private static String IP = "192.168.2.161";
private static String DBName = "tisman";
private static String USER = "sa";
private static String PWD = "bluegloom";
/** 创建数据库对象 */
private static Connection getSQLConnection() {
Connection con = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://" + IP + ":1433/" + DBName + ";useunicode=true;characterEncoding=UTF-8", USER, PWD);
} catch (ClassNotFoundException e) {
System.out.print(e.getMessage());
} catch (SQLException e) {
System.out.print(e.getMessage());
}
return con;
}

    /** 查询数据库 */
    public static String Query() {
        String result = "";
        try {
            Connection conn = getSQLConnection();
            String sql = "select top 1 * from Users";
            Statement stmt = conn.createStatement();//
            ResultSet rs = stmt.executeQuery(sql);
            while (rs.next()) {
                String s1 = rs.getString("id");
                String s2 = rs.getString("password");
                result += s1 + "  -  " + s2 + "\n";
            }
            rs.close();
            stmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
            result += "查询数据异常!" + e.getMessage();
        }
        return result;
    }

}

运行到class.forname处就报异常
配置如图片说明
下:[图片]

1个回答

SQL sever的TCP协议启用了吗?

yangsj85
bluegloom 回复酒鸠: 用telnet ping不通1433端口
8 个月之前 回复
qq_37235979
酒鸠 回复bluegloom: 那我就不知道啦0.0
8 个月之前 回复
yangsj85
bluegloom 启用了,你能帮我远程看看吗,qq406179485
8 个月之前 回复
qq_37235979
酒鸠 ...看见了,SQL sever的TCP协议启用了吗
8 个月之前 回复
yangsj85
bluegloom 导入了,在上面
8 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!