運行本程序前需安裝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 閱讀(88)
評論(0) 編輯 收藏