各位大侠,最近学习安卓,用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();
}
}
}