JDBC 版本 jdbc for sql server 2000 sp3
Driver Information
  Driver Name: SQLServer
  Driver Version: 2.2.0040Database Information 
  Database Name: Microsoft SQL Server
  Database Version: Microsoft SQL Server 2000 - 8.00.760 (Intel X86) 
  Dec 17 2002 14:22:05 
  Copyright (c) 1988-2003 Microsoft Corporation
  Developer Edition on Windows NT 5.0 (Build 2195: Service Pack 4)网络环境:都在一个局域网中,10M的速度我遇到的问题:
本地连接的速度(秒)
****cost time:0.25***
网络连接的速度(秒)
****cost time:4.781***为什么如此慢?附件是我的测试程序. 请高人指点 测试代码:
//*********************************************************
public class Connect{
     private java.sql.Connection  con = null;
     private final String url = "jdbc:microsoft:sqlserver://";
     private final String serverName= "10.0.0.197";
     private final String portNumber = "1433";
     private final String databaseName= "pubs";
     private final String userName = "sa";
     private final String password = "sa";
     //private final String password ="sa";
     // Informs the driver to use server a side-cursor,
     // which permits more than one active statement
     // on a connection.
     private final String selectMethod = "cursor";     // Constructor
     public Connect(){}     private String getConnectionUrl(){
          return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
     }     private java.sql.Connection getConnection(){
          try{
               Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
               long startTime = System.currentTimeMillis();
               con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
               long endTime = System.currentTimeMillis();
               System.out.println("****cost time:"+((endTime-startTime)/1000.0)+"***");
               if(con!=null) System.out.println("Connection Successful!");
          }catch(Exception e){
               e.printStackTrace();
               System.out.println("Error Trace in getConnection() : " + e.getMessage());
         }
          return con;
      }     /*
          Display the driver properties, database details
     */     public void displayDbProperties(){
          java.sql.DatabaseMetaData dm = null;
          java.sql.ResultSet rs = null;
          try{
               con= this.getConnection();
               if(con!=null){
                    dm = con.getMetaData();
                    System.out.println("Driver Information");
                    System.out.println("\tDriver Name: "+ dm.getDriverName());
                    System.out.println("\tDriver Version: "+ dm.getDriverVersion ());
                    System.out.println("\nDatabase Information ");
                    System.out.println("\tDatabase Name: "+ dm.getDatabaseProductName());
                    System.out.println("\tDatabase Version: "+ dm.getDatabaseProductVersion());
                    System.out.println("Avalilable Catalogs ");
                    rs = dm.getCatalogs();
                    while(rs.next()){
                         System.out.println("\tcatalog: "+ rs.getString(1));
                    }
                    rs.close();
                    rs = null;
                    closeConnection();
               }else System.out.println("Error: No active Connection");
          }catch(Exception e){
               e.printStackTrace();
          }
          dm=null;
     }     private void closeConnection(){
          try{
               if(con!=null)
                    con.close();
               con=null;
          }catch(Exception e){
               e.printStackTrace();
          }
     }
     public static void main(String[] args) throws Exception
       {
          Connect myDbTest = new Connect();
          myDbTest.displayDbProperties();
       }
}//********************************************************

解决方案 »

  1.   

    其它机子连我的机器是:
    ****cost time:2.141***我本机连接的结果:
    ****cost time:0.813***
    Connection Successful!
    Driver Information
    Driver Name: SQLServer
    Driver Version: 2.2.0029Database Information 
    Database Name: Microsoft SQL Server
    Database Version: Microsoft SQL Server  2000 - 8.00.760 (Intel X86) 
    Dec 17 2002 14:22:05 
    Copyright (c) 1988-2003 Microsoft Corporation
    Personal Edition on Windows NT 5.1 (Build 2600: Service Pack 2)Avalilable Catalogs 
    catalog: master
    catalog: msdb
    catalog: Northwind
    catalog: oa
    catalog: pubs
    catalog: tempdb
    差不多吧. 没什么问题
      

  2.   

    你的机器性能不行吧,换个jdbc驱动试试