T
Tage V. Madsen
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");
}
}
}
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");
}
}
}