JAVA SQLSERVER 连接
我写了一个连接SQLSERVER的类,但是报错
com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect
大家帮忙看看代码哪里错了
package cn.ctgu.edu.ac;
import java.sql.*;
public class connect {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String url="jdbc:sqlserver://localhost:1433;Database=网上书店管理系统;integratedSecurity=true;"; //用widows身份登录
String sql="select * users";
Connection conn=null;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn=DriverManager.getConnection(url);
Statement SQLStatement=conn.createStatement();
ResultSet rt=SQLStatement.executeQuery(sql);
while(rt.next())
{
System.out.println(rt.getInt("userID")+""+rt.getString("username"));
}
if(rt!=null)
{
rt.close();
}
if(SQLStatement!=null)
{
SQLStatement.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
还有,在url中的端口号应该是IPAll中的哪一个?