BindException (Address already in use) when connecting to MSSQL

From: Tage V. Madsen (dontusethismuch_at_yahoo.dk)
Date: 07/06/04


Date: 6 Jul 2004 06:51:34 -0700

I'm experiencing a problem with JDBC and MSSQL 2000, now and again
DriverManager.getConnection() throws a java.net.BindException, with
this message:

TCP/IP connection failed to host:java.net.BindException: Address
already in use: connect
url:jdbc:JSQLConnect://localhost:1433/database=DBx/

I've boiled the problem down to an example - listed below, after
connecting approx. 3960 times the exception is thrown - on my 3 Ghz
PC, on slower ones it works, so it must be timing-related...

To verify that MSSQL is working, I've created a similar app in
VC++/ODBC, and there it works fine - I can connect 100000 times
without problems.

I'm using JNetDirect's JDBC driver, but I've also tried the MS driver,
same behaviour. The use of DriverManager instead of a (pooled)
DataSource is merely for simplicity, the behaviour is, again, the
same, either way.

Any help will be greatly appreciated.

Code:

import java.sql.*;

public class Tester {
        public static void main(String[] args) {
         try
         {
          Class.forName("com.jnetdirect.jsql.JSQLDriver");
         }
         catch(ClassNotFoundException e)
         {
         }
         for (int i=0;i<100000;i++)
         {
          justconn();
          System.out.println("Did: "+i);
         }
        }
        
        private static Connection getconn()
        {
         try
         {
           String url="jdbc:JSQLConnect://localhost:1433/database=DBx/";
          return DriverManager.getConnection(url,"sa","sa");
         }
         catch(SQLException es)
         {
           System.out.println("too bad "+es.getMessage()); // Exception!!!
         }
         return null;
          }
          
        private static void justconn()
        {
          try{
           Connection con = getconn();
           con.close();
          }
          catch(SQLException e)
          {
            System.out.println("bad");
          }
        }
}



Relevant Pages

  • Re: VB.NET vs CFMX tick count distribution?
    ... it supports JDBC and ODBC via the JDBC ... .NET supports MSSQL through a native driver without using ...
    (microsoft.public.dotnet.languages.vb)
  • Re: VB.NET vs CFMX tick count distribution?
    ... it supports JDBC and ODBC via the JDBC ... it also supports MSSQL via a native JDBC driver ... Isn't this still slower than the .sqlclient driver VB.NET will use, ...
    (microsoft.public.dotnet.languages.vb)
  • Problem with mssql jdbc
    ... I can't connect with jdbc for mssql. ... } catch (ClassNotFoundException e) { ... [SQLServer 2000 Driver for JDBC]Error ...
    (comp.lang.java.programmer)
  • Re: Acessing MS sql from Solaris
    ... Microsoft SQL Server 2000 Driver for JDBC ... delete both the log.txt file and the installation directory. ...
    (comp.unix.shell)
  • Re: Acessing MS sql from Solaris
    ... Microsoft SQL Server 2000 Driver for JDBC ... delete both the log.txt file and the installation directory. ...
    (comp.unix.shell)