jtds1.1连接sqlserver2000测试示例
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:publicclassTestSqlserverJtds{publicstaticvoidmain(String[]arg...
复制代码 代码如下:
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();
}
}
}
}