com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1456 连接到主机 localhost 的 TCP/IP 连接
刚装的SQLSERVER2008无法用MYECLIPSE总是无法连接,报错com.microsoft.sqlserver.jdbc.SQLServerException:...
刚装的SQL SERVER2008无法用MYECLIPSE总是无法连接,报错
com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1456 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1049)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at pinhong.dao.DataBaseDao.getCon(DataBaseDao.java:10)
at pinhong.dao.text.main(text.java:14)
测试代码
连接数据库
package pinhong.dao;
import java.sql.*;
public class DataBaseDao {
public final static String DRIVER ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
public final static String URL = "jdbc:sqlserver://localhost:1456;DataBaseName=pinhong;";
public final static String NAME = "sa";
public final static String PASSWORD = "suiwind5211314";
public Connection getCon() throws ClassNotFoundException, SQLException{
Class.forName(DRIVER);
Connection con = DriverManager.getConnection(URL, NAME, PASSWORD);
return con;
}
}
测试
package pinhong.dao;
import java.sql.*;
public class text {
/**
* @param args
*/
public static void main(String[] args) {
Connection con = null;
DataBaseDao dbo = new DataBaseDao();
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
con = dbo.getCon();
pstmt = con.prepareStatement("select * from TBL_USER");
rs = pstmt.executeQuery();
while(rs.next()){
System.out.println(rs.getString(1));
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
已经用JDBC了可是就是连接不上,1433端口不好使之后我又用了别的端口
貌似是端口没有启动,求大侠帮助 展开
com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1456 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1049)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at pinhong.dao.DataBaseDao.getCon(DataBaseDao.java:10)
at pinhong.dao.text.main(text.java:14)
测试代码
连接数据库
package pinhong.dao;
import java.sql.*;
public class DataBaseDao {
public final static String DRIVER ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
public final static String URL = "jdbc:sqlserver://localhost:1456;DataBaseName=pinhong;";
public final static String NAME = "sa";
public final static String PASSWORD = "suiwind5211314";
public Connection getCon() throws ClassNotFoundException, SQLException{
Class.forName(DRIVER);
Connection con = DriverManager.getConnection(URL, NAME, PASSWORD);
return con;
}
}
测试
package pinhong.dao;
import java.sql.*;
public class text {
/**
* @param args
*/
public static void main(String[] args) {
Connection con = null;
DataBaseDao dbo = new DataBaseDao();
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
con = dbo.getCon();
pstmt = con.prepareStatement("select * from TBL_USER");
rs = pstmt.executeQuery();
while(rs.next()){
System.out.println(rs.getString(1));
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
已经用JDBC了可是就是连接不上,1433端口不好使之后我又用了别的端口
貌似是端口没有启动,求大侠帮助 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询