I have SQL Server Installed and now I want to use it for JDBC connectivity. I have enabled the TCP/IP connection via manager and Mixed mode authentication via Object explorer properties. Now my connection statement says
Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver" ); // no error
Connection c = DriverManager.getConnection( "jdbc:sqlserver://localhost:1433;databaseName=student;user=gagan;password=35795200");
where gagan is my username and 35795200 is my windows login password. I still get the login failed exception. I am really fed up with this. Please help !
Your URL includes username and password. Try calling getConnection(URL, username, password) method. URL is in the form jdbc:subprotocol:subname
It may be database=
not databasename
. If that does not work, check if you are able to login with these credentials. Instead of this, There is nothing wrong with connection string. Specify which version of MSSQL you are using.
Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver" ); // no error
Connection c = DriverManager.getConnection( "jdbc:sqlserver://WAHEGURU_HP;database=student;user=WAHEGURU\\gagan;password=35795200");
Examples of connection string:
/ * ** * ** * ** * ** * ** * ** * ** * ** * ** * **** / Connect to the default database on the local computer by using integrated authentication:
jdbc:sqlserver://localhost;integratedSecurity=true;
Connect to a named database on a remote server:
jdbc:sqlserver://localhost;databaseName=AdventureWorks;integratedSecurity=true;
Connect on the default port to the remote server:
jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks;integratedSecurity=true;
Connect by specifying a customized application name:
jdbc:sqlserver://localhost;databaseName=AdventureWorks;integratedSecurity=true;applicationName=MyApp;
/ * ** * ** * ** * ** * ** * ** * ** * ** * ** * **** /
Please paste screen shot of error , this will help to resolve this
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.