运行本程序前需安装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();
}
}
}
运行结果:
posted on 2007-05-25 22:25
jadmin 阅读(85)
评论(0) 编辑 收藏