Reputation: 83
I am trying to connect to MS SQL Server 2005 from java, I am getting the following error, can anyone help me ?
private static final String DRIVER_CLASS = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
Class.forName(DRIVER_CLASS);
DriverManager.getConnection("jdbc:sqlserver://localhost:1433","sa","root");
I added the following 5 jar files :
The exception is :
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
Upvotes: 1
Views: 4496
Reputation: 1941
Please check what protocols are enabled on the server. Go to Start/Programs/Microsoft |SQL Server 2005/Configuration Tools/SQL Server Configuration Manager. Check if tcp is enabled under SQL Server 2005 Network Configuration/Protocols for MSSQLSERVER.
Please check if you don't have named instance - SQL Server Express edition by default creates a named instance for example.
And the third - check if SQL Server has mixed mode authentication - if not it will not allow you to connect using SQL login and password. BTW it is a bad idea to use sa account to develop applications.
Upvotes: 1
Reputation: 12235
Is you firewall on? If so, maybe you will need to make an exception for port 1433
Upvotes: 1