Java中SQL Server 2000数据库的连接(连接测试)
运行本程序前需安装SQL Server 2000 Driver for JDBC Service Pack 3
测试代码如下:
// 导入Java SQL包,连接数据库必需;
import java.sql.*;
public class TestDB
{
public static void main(String[] args)
{
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=pubs";
String userName = "sa";
String userPwd = "14579";
Connection dbConn;
try
{
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
运行结果:
![](http://hiphotos.baidu.com/jadmin/pic/item/b94226305708259ca9018ec9.jpg)