Link to home
Start Free TrialLog in
Avatar of kameshwari
kameshwari

asked on

Error establishing socket on MS SQL JDBC driver

Hi!

I'm a beginner in Java trying to learn JDBC.
I have downloaded and installed the MS SQL JDBC driver type 4. I've followed the tutorial and some code on the net and written the following program:

import java.sql.*;

public class DBWork{

      private Connection conn = null;

      public static void main(String args[]){

            DBWork work = new DBWork();
      }

      public DBWork(){
            try{
                  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                  conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://server123:1433;Database=Dbxyz;User=sa;Password=abc");
                  Statement stm = conn.createStatement();
                  ResultSet rs = stm.executeQuery("select * from ServiceAreas");
                  while (rs.next()){
                        System.out.println(rs.getString("AreaIdVc"));
                        System.out.println(rs.getString("Namevc"));
                  }
            }
            catch (ClassNotFoundException e1){
                  System.out.println("ClassNotFoundException: "+e1.getMessage());
            }
            catch (SQLException e2){
                  System.out.println("SQLException: " +e2.getMessage());
            }
            finally{
                  try{
                        if (conn != null){
                              conn.close();
                        }
                  }catch (SQLException e3){}
            }
      }
}

But I get the following error when I run the program. The error occurs on the DriverManager.getConnection line:

SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.

I've searched the web extensively for a solution. Infact I put the port number '1433' after going through some forums. I have checked the port the SQL server is listening to and it is 1433. The error still persists.

Has anyone got a solution for this problem? I have already spent an entire day on this.

Thanks in advance.
Kameshwari.

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kameshwari
kameshwari

ASKER

Thanks CEHJ. I had already tried that but didn't what was to be done next. I tried setting another port in Server Network Utility of the SQL server, but the program got hung then. Anyway, I have just found the solution. I had to set 1433 in my Client Network Utility (on the client machine accessing the SQL server). It works just fine now. Thanks a lot anyway.
:-)