Solved

Error establishing socket on MS SQL JDBC driver

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java JRE greater than 1.6 5 50
split string containing \r\n in Java 46 38
xampp tool 12 26
javap not working 8 37
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now