错误代码:com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect无法连接
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at dao.BaseDao.getConnection(BaseDao.java:21)
at dao.impl.ImageDaoImpl.cha(ImageDaoImpl.java:22)
at text.ImageText.main(ImageText.java:28)
Exception in thread "main" java.lang.NullPointerException
at dao.impl.ImageDaoImpl.cha(ImageDaoImpl.java:25)
at text.ImageText.main(ImageText.java:28)
SQL链接语句累:
private static String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static String url="jdbc:sqlserver://localhost:1433;DataBaseName=shangyi";
private static String user="princethestar";
private static String password ="Loveyou";
public Connection getConnection(){
try {
Class.forName(driver);
conn=DriverManager.getConnection(url,user,password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.print("无法找到驱动");
} catch (SQLException e) {
e.printStackTrace();
System.out.println("无法连接");
}
return conn;
}
后面附有服务开启图片和协议开启图片 SQL Server 2008版本 |
|