Solved

Error establishing socket on MS SQL JDBC driver

Posted on 2003-10-22
3
414 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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
backtracking recursion  code 19 57
stackato and cloud 4 85
xampp tool 12 48
hibernate jars 4 27
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

808 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