CJ_Finger 2016-09-11 04:05 采纳率: 100%
浏览 1127
已采纳

关于连接数据库的问题

各位大侠,最近学习安卓,用Strust2写了个服务器来访问SQL sever 2008数据库,本机测试没问题,app安装到手机然后用局域网,也没问题,但是放到服务器之后,就提示

 The TCP/IP connection to the host localhost, port 1433 has failed. Error: Connection refused: connect. Please verify the connection properties and check that a SQL Server instance is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.

SQL的TCP/IP我已经开启了,JDBC包也放到tomcat的lib里了,防火墙也已经关闭了,但就是获取不了连接,请问这是什么原因?下面是连接数据库的代码:

 public class DBConnect {
    private static  String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
    private static  String url="jdbc:sqlserver://localhost:1433;DatabaseName=WanShang";
    static Connection con;

    public static Connection getCon(){
       try{
           Class.forName(driver);
           con = DriverManager.getConnection(url,"no2","123");
       }catch(Exception e){
           e.printStackTrace();
       }
       return con;
    }

    public static void  closeCon(Connection con){
       try{
           if(con!=null || !con.isClosed()){
               con.close();
           }
       }catch(Exception e){
           e.printStackTrace();
       }
    }
}

  • 写回答

2条回答

  • 正汰 2016-09-11 04:51
    关注

    是在外网访问内网数据库吗,如果是的话,你的交换机或路由可能阻止你访问内网

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料