代碼如下:
public class TestSqlserverJtds {
public static void main(String[] args) {
Connection con=null;
try
{
String driver="net.sourceforge.jtds.jdbc.Driver";
String url="jdbc:jtds:sqlserver://192.168.0.15:1433;DatabaseName=test";
Class.forName(driver).newInstance();
System.out.println(" 連接開始。。。。。。");
long starttime = System.currentTimeMillis();
con =DriverManager.getConnection(url,"sa","123");
long endtime = System.currentTimeMillis();
System.out.println(" 連接成功 !Lost time:" + (endtime - starttime) / 1000 + "秒");
con.close();
} catch(Exception e) {
e.printStackTrace();
} finally{
try {
if(null != con){
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}