Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JDBC MS SQLserver extremely slow connection...

843854Jul 30 2002 — edited Jul 30 2002
Hello,

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





Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 27 2002
Added on Jul 30 2002
2 comments
276 views