下載SQL Server驅動器
地址:https://www.microsoft.com/zh-CN/download/details.aspx?id=57782
運行exe文件 放到某一目錄
打開JAVA項目
點擊Project--》properties--》Libraries--》Add External JARs...
根據需求組選擇版本 我用的是11.0 所以選擇的是11.0版本
選擇後 點擊 Apply and Close
驅動導入成功 進行連接測試
public static void main(String[] args) throws Exception{
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=ET_Lock;;integratedSecurity=true;";
String userName="sa";
String userPwd="123456";
try
{
Class.forName(driverName);
Connection conn=DriverManager.getConnection(dbURL,userName,userPwd);
System.out.println("連接數據庫成功");
}catch(Exception e)
{
e.printStackTrace();
System.out.print("連接失敗");
}
}