Solved

Error establishing socket on MS SQL JDBC driver

Posted on 2003-10-22
3
412 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
Comment Utility
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
Comment Utility
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
Comment Utility
:-)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
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:

763 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

11 Experts available now in Live!

Get 1:1 Help Now