Sql exception com.microsoft.sqlserver.jdbc.sqlserverexception: login failed for user ''. Clientconnectionid:073b35b2-0e56-460d-8353-9de2b2d0ecff
<p>I am Using Windows Authentication (Please kept in mind).</p>

<p>As there is no user name and password.</p>

<p>then</p>

<p>why the following code gives me error?</p>

<pre><code>public class Conection
{
public static void main(String a[]) throws ClassNotFoundException, SQLException
{
    try
    {
        String url = "jdbc:sqlserver://localhost\\MALIKUSMANNAWAZ:1433;databaseName=ali";   
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection conn = DriverManager.getConnection(url);
        System.out.println("connection created");
        Statement st=conn.createStatement();
        String sql="select * from Login_System";
        ResultSet rs=st.executeQuery(sql);
        while(rs.next())
        {
            System.out.println("Name: "+rs.getString(1));
            //System.out.println("Address : "+rs.getString(2));
        }
        if(st!=null)
        st.close();
        if(conn!=null)
            conn.close();
    }
    catch(SQLException sqle)
    {
        System.out.println("Sql exception "+sqle);
    }
}
}
</code></pre>

<p>Please Kept in mind that my PC Name is:</p>

<pre><code>MALIKUSMANNAWAZ
</code></pre>

<p>using:</p>

<pre><code>Windows Authentication
</code></pre>

<p>Database Name:</p>

<pre><code>ali
</code></pre>

<p>IDE:</p>

<pre><code>SQL Server 2012
</code></pre>