Receiving SQLException “Login failed for user” connecting to SQL Server 2008

后端 未结 4 1504
忘了有多久
忘了有多久 2020-12-19 06:07

I am trying to connect to SQL Server 2008 via Java.

  1. I\'ve added sqljdbc4.jar to my project\'s library.
  2. No username and password is set fo
相关标签:
4条回答
  • 2020-12-19 06:24

    I had the same issue. Its because of the wrong format of the ConnectionUrl. You are missing username and password in the ConnectionUrl.

    String ConnectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=DB","username","password");"
    

    I hope it works well!!!

    0 讨论(0)
  • 2020-12-19 06:25

    I was having same issue when I tried to connect to Microsoft SQL server from Java. I used jTDS driver instead of regular SQLJdbdc Driver.

            Class.forName("net.sourceforge.jtds.jdbc.Driver"); 
            String connectionUrl = "jdbc:jtds:sqlserver://localhost:1433;databaseName=DB;integratedSecurity=true";
            Connection con = DriverManager.getConnection(connectionUrl);
    
    0 讨论(0)
  • 2020-12-19 06:27

    This post my help: jdbc.SQLServerException: Login failed for user for any user

    You need the integratedSecurity=true flag and make sure the server properties are indeed set to 'Windows Authentication Mode' under Security.

    0 讨论(0)
  • 2020-12-19 06:36

    If you want windows authentication you need to add the option integratedSecurity=true to your JDBC URL:

    jdbc:sqlserver://localhost:1433;databaseName=DB;integratedSecurity=true
    

    You also need sqljdbc_auth.dll (beware of 32/64 bit) in your Windows system path or in a directory defined through java.library.path

    For details see the driver's manual: http://msdn.microsoft.com/en-us/library/ms378428.aspx#Connectingintegrated

    0 讨论(0)
提交回复
热议问题