Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 984423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:00:47+00:00 2026-05-16T05:00:47+00:00

I am writing a java code to connect with MS SQL Server 2005. MS

  • 0

I am writing a java code to connect with MS SQL Server 2005. MS SQL Server is on Remote server windows server 2003. I am trying the following code but i am unable to establish a connection:

import java.*;

public class Connect {
     private java.sql.Connection con = null;
     private final String url = "jdbc:sqlserver://";
     private final String serverName="xxx.xxx.xxx.xxx"; 
     private final String portNumber = "1433";
     private final String databaseName="myDb"; 
     private final String userName ="user1";
     private final String password = "xxxx";     
     private final String selectMethod = "cursor";

     // Constructor
     public Connect() {}

     private String getConnectionUrl() {
          return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
     }

     private java.sql.Connection getConnection() {
          try {
              Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
              con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
               if(con!=null) System.out.println("Connection Successful!");
          } catch(Exception e) {
               e.printStackTrace();
               System.out.println("Error Trace in getConnection() : " + e.getMessage());
         }
          return con;
      }

     /*
          Display the driver properties, database details
     */

     public void displayDbProperties() {
                    System.out.println("Perform Operations ");

     }

     private void closeConnection() {
          try{
               if(con!=null)
                    con.close();
               con=null;
          }catch(Exception e){
               e.printStackTrace();
          }
     }
     public static void main(String[] args) throws Exception {
          Connect myDbTest = new Connect();
         // myDbTest.displayDbProperties();
     }
}

But I am getting following exceptions:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host  has failed. java.net.ConnectException: Connection refused: connect
        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
Error Trace in getConnection() : The TCP/IP connection to the host  has failed. java.net.ConnectException: Connection refused: connect
Error: No active Connection

I am not getting where is the problem in the above code or do i need to do some setting
to connect to remote server.

Please give me your valuable suggestion which can help me to overcome with this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:00:48+00:00Added an answer on May 16, 2026 at 5:00 am

    IMHO “Connection refused” means your database server is not visible from your application server.

    • Check IP address and port.
    • Check database connectivity directly from your database server (to avoid firewalls).
    • Check database connectivity from your application server.

    Hope this will help you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 506k
  • Answers 506k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, don't avoid regular expressions. They're actually quite a nifty… May 16, 2026 at 3:43 pm
  • Editorial Team
    Editorial Team added an answer It means that when you declare the parameter struct timespec… May 16, 2026 at 3:43 pm
  • Editorial Team
    Editorial Team added an answer Line 99: memcpy(floats, ints, sizeof(floats)); is partially initializing floats[] effectively… May 16, 2026 at 3:43 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a year's experience writing client code but none with server stuff. I
I am running a simple Java client to connect to a remote MQ queue.
I'm writing test code to test a client-server application. The application under test consists
I've almost finished writing a HTTP/1.0 compliant web server under Java (no commercial usage
I am writing a small utility to send JMS messages to a remote server,
I am writing JVMTI code to profile Java programs, which mostly entails obtaining stack
I'm writing my code in Haxe. This is quite irrelevant to the question though,
I'm following the sample code in CFNetwork Programming Guide , specifically the section on
I'm writing a class in Java to represent a Graph data structure. This is
I'm currently writing a JNI project where I'm getting the following error log when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.