The reasons for the error are as follows:
Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Cannot open connection at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449) at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160) at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81) at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473) at vo.NewsManager.main(NewsManager.java:17) Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Connect to the host via port 1433 localhost Of TCP/IP Connection failed. error:"Connection refused: connect. Verify the connection properties and check SQL Server Instances are running on the host and accepted on this port TCP/IP Connect, and make sure that the firewall does not block access to this port TCP Connect. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1033) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:154) at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
On the command line, enter telnet localhost 1433, which cannot be connected:
Check Configuration: Peripheral Application Configurator for Services and Connections
"Use TCP/IP and named pipes(B)" has been selected.
Next, check the SQL Server Configuration Manager
TCP/IP under the instance name "SQLEXPRESS" has been started:
Right-click "TCP/IP" to select "Properties" (or double-click "TCP/IP") and select the "IP Address" tab, with "IPALL" at the bottom:
Here's the problem: I haven't set up a TCP port. After that, the following figure is shown:
Look at the "SQL Native Client Configuration":
Double-click "TCP/IP":
Everything is right. Now restart the service:
Right-click "SQL Server (SQLEXPRESS)" and select Restart.
Go back to the command line and type: telnet localhost 1433
Display black screen, as shown above, shows that it has been successful! ____________
Finally, the JDBC connection under Eclipse can be correctly connected to SQL Server 2005.
Note:
Screen software: QQ
Image editing software: mspaint