Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Java
import java.sql.*;
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);
        }
    }
}


What I have tried:

Using Windows Authentication Only...
Posted
Updated 27-Jun-16 15:03pm
v2
Comments
ZurdoDev 26-Jun-16 8:03am    
Since the error gives a blank username that is what is being passed to sql, a blank user name. You need to provide a user name.
Stack Holder 26-Jun-16 14:40pm    
I am just using Window Authentications Onlyyyyyyyyyyyyyyyyyyyy....

You have to kept in mind that in Windows Authentications there are no user name and password (if any it maybe,but i am not using any user name and password).
Stack Holder 26-Jun-16 14:42pm    
Please help me as soon as possible, i am in trouble.
Daniel Jones 27-Jun-16 0:13am    
Right click on SQL > proprieties > security > select SQL server and windows authentication mode
Stack Holder 27-Jun-16 9:31am    
In Security, there is no "SQL server and windows authentication mode"

1 solution

Solved:

Java
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost\\MALIKUSMANNAWAZ:1433;databaseName=ali","sa","dbase");
           System.out.println("connection created");
           Statement st=conn.createStatement();
           String sql="select * from Login_System";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900