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();
}
}//********************************************************
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();
}
}//********************************************************
解决方案 »
- android<Intent-filter>配置的问题
- 关于JAVA类加载双亲委派的迷惑,讲清楚直接给分
- 在JAVA中播放视频文件
- 下面这个程序有错误!!请求帮助!!
- 为什么我打包进字节流..里面每个数据之间会有"0"隔开,也就是null
- java访问sqlserver2000出现的奇怪问题,请高手帮忙!谢谢
- ##### 这个问题可能有点难,请教高人指点 #####
- 拜托!老兄们,有谁知道使用JBUILDR下的CORBA?(毕业设计啊,很惨啊:)!)
- 中秋大喜!!!(升级啦,散分哟!)
- 给我推荐几本 JAVA 的书吧先谢谢了!
- JComboBox里面内容太长看不完整的问题
- eclipse如何支持可视化
****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
差不多吧. 没什么问题