JDBC MS SQLserver extremely slow connection...
843854Jul 30 2002 — edited Jul 30 2002Hello,
I have downloaded the JDBC driver from Microsoft (http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.asp?url=/MSDN-FILES/027/001/779/msdncompositedoc.xml).
I ran it from RedHat Linux (7.2) with JDK 1.4, calling SQLserver running on WIN2000 server.
Here is my code (very simple) -
===========================================
import java.sql.*;
import java.util.*;
public class TestSQL {
public static void main (String[] arg) {
try {
String query = "SELECT * FROM publishers";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.22:1433", "alex", "xxxx");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String pub_id = rs.getString("pub_id");
String pub_name = rs.getString("pub_name");
String city = rs.getString("city");
String country = rs.getString("country");
System.out.println(pub_id + " -- " + pub_name + " -- " + city + " -- " + country);
}
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
===============================================================
The result looks fine (a total of 8 rows retrieved).
But it took a total of (5.3s real, 2.8s user, 0.05s sys).
In particular -
Class.forName() took 1.5 seconds,
DriverManager.getConnection() took 2.5 seconds.
Did I do anything wrong? (my TCP/IP connection to the database server is fine, and i don't expect this being the problem.) or has anyone had similar experience?
Any help is greatly appreciated.
thanks,
alex