下载SQL Server驱动器

地址:https://www.microsoft.com/zh-CN/download/details.aspx?id=57782

运行exe文件 放到某一目录

在Eclipse中连接SQL Server 2012数据库

打开JAVA项目 

点击Project--》properties--》Libraries--》Add External JARs...

 

在Eclipse中连接SQL Server 2012数据库

根据需求组选择版本  我用的是11.0 所以选择的是11.0版本

在Eclipse中连接SQL Server 2012数据库

选择后 点击 Apply and Close

在Eclipse中连接SQL Server 2012数据库

驱动导入成功 进行连接测试

    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("连接失败");

          }           
          
    }

相关文章: