Solved

Error establishing socket on MS SQL JDBC driver

Posted on 2003-10-22
3
419 Views
Last Modified: 2012-05-04
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.

0
Comment
Question by:kameshwari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 9597240
It could be your network settings, Try telnetting thus:

telnet xxx.xxx.xxx.xxx 1433

where xxx.xxx.xxx.xxx is the IP address of server123

If you can't, see your network admin
0
 

Author Comment

by:kameshwari
ID: 9597361
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9597367
:-)
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question