Results 1 to 3 of 3
  1. #1
    ddatta8 is offline Member
    Join Date
    Dec 2008
    Rep Power

    Default Connect to SQL Server


    I have the following code to connect to SQL server and below it, I have given the error I am getting when trying to run it. Is it the port number or does it look like an id/password problem? Please help.
    Java Code:
    package testconnection;
    import java.sql.*;
    public class Main {
        public static void main(String[] args) {
            DB db = new DB();
    class DB
        public DB() {}
        public void dbConnect(String db_connect_string, String db_userid, String db_password)
                Connection conn = DriverManager.getConnection(db_connect_string, db_userid, db_password);
            catch (Exception e)
    java.sql.SQLException: Network error IOException: Connection refused: connect
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(C
    at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(C
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.ja va:178)
    at java.sql.DriverManager.getConnection(DriverManager .java:582)
    at java.sql.DriverManager.getConnection(DriverManager .java:185)
    at testconnection.DB.dbConnect(
    at testconnection.Main.main(
    Caused by: Connection refused: connect
    at Method)
    at .java:333)
    at ava:182)
    at ava:366)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De
    at java.lang.reflect.Method.invoke(
    at net.sourceforge.jtds.jdbc.SharedSocket.createSocke tForJDBC3(
    at net.sourceforge.jtds.jdbc.SharedSocket.<init>(Shar
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(C
    ... 6 more
    BUILD SUCCESSFUL (total time: 1 second)
    Last edited by ddatta8; 03-04-2010 at 02:22 AM. Reason: none

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    i believe connection revused means it could not physically connect to the database service socket on that machine. For example, if the database is running, and has been configured to allow TCP/IP connections from external hosts at the IP address you are coming from, perhaps the box itself is running a windows firewall that is preventing any traffic external to the machine where the database software is running from connecting to it.

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


    Connection refused means that the server saw the connection request and didn't like it. Check your JDBC URL...

Similar Threads

  1. Connect to SQL server 2005
    By comp in forum JDBC
    Replies: 1
    Last Post: 03-26-2009, 12:25 AM
  2. multi clients connect to udp server
    By bachma7 in forum Networking
    Replies: 5
    Last Post: 12-12-2008, 09:56 PM
  3. Problem connect to SQL Server
    By Crisanto in forum Eclipse
    Replies: 1
    Last Post: 12-02-2008, 01:13 AM
  4. Server not able to connect client
    By Kapil Gupta in forum New To Java
    Replies: 15
    Last Post: 07-22-2008, 05:09 AM
  5. connect to web server from mobile using java app.
    By jankrishnan in forum Advanced Java
    Replies: 1
    Last Post: 07-15-2008, 05:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts