import java.sql.*;
import java.util.ArrayList;
import java.io.IOException;import excelorword.Treebean;
import excelorword.ReadFile;
import kq_search.Kq_lookbean;public class Test{
public static void main(String args[]) throws ClassNotFoundException, SQLException {
long startTime=System.currentTimeMillis(); //获取开始时间
Connection conn=null;/* 100*/ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
/* 101*/ String url="jdbc:microsoft:sqlserver://192.168.100.248:1433;DatabaseName=g4pro";
conn= DriverManager.getConnection(url, "eip", "eip"); PreparedStatement pstat = null;
ResultSet rs = null;
String sql = null;
sql = "select empname from kq_workday where id='122'";
try{
pstat = conn.prepareStatement(sql);
rs = pstat.executeQuery();
while (rs.next()) { System.out.println(rs.getString("empname"));
}
}
catch (Exception e ){
System.out.println(e);
}
rs.close();
pstat.close();
conn.close();long endTime=System.currentTimeMillis(); //获取结束时间
System.out.println("程序运行时间: "+(endTime-startTime)+"ms");
}
}这个是远程访问服务器上的sql_server
结果:
许立霞
程序运行时间: 4671ms我访问我本机上的sql_server速度就超快
结果是:
许立霞
程序运行时间: 371ms
高手请教下高手!
静侯佳音
import java.util.ArrayList;
import java.io.IOException;import excelorword.Treebean;
import excelorword.ReadFile;
import kq_search.Kq_lookbean;public class Test{
public static void main(String args[]) throws ClassNotFoundException, SQLException {
long startTime=System.currentTimeMillis(); //获取开始时间
Connection conn=null;/* 100*/ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
/* 101*/ String url="jdbc:microsoft:sqlserver://192.168.100.248:1433;DatabaseName=g4pro";
conn= DriverManager.getConnection(url, "eip", "eip"); PreparedStatement pstat = null;
ResultSet rs = null;
String sql = null;
sql = "select empname from kq_workday where id='122'";
try{
pstat = conn.prepareStatement(sql);
rs = pstat.executeQuery();
while (rs.next()) { System.out.println(rs.getString("empname"));
}
}
catch (Exception e ){
System.out.println(e);
}
rs.close();
pstat.close();
conn.close();long endTime=System.currentTimeMillis(); //获取结束时间
System.out.println("程序运行时间: "+(endTime-startTime)+"ms");
}
}这个是远程访问服务器上的sql_server
结果:
许立霞
程序运行时间: 4671ms我访问我本机上的sql_server速度就超快
结果是:
许立霞
程序运行时间: 371ms
高手请教下高手!
静侯佳音
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货