在Eclipse中连接SQL Server 2012数据库

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

          }           
          
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章