#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    SqlServer: JDBC Login failed for user


    I've written a very simple jdbc login test program. And after all kinds of problems I've almost got it working. Almost, just can't seem to get past this "SQLServerException: Login failed for user xxxxx" problem.

    I created a simple database PersonInfo then I created user user1 password1 (sql authenication). And after trying everything was unable to connect to the database.

    I am using SqlServer2008 on Win 7, I'v got the latest jdbc driver from Microsoft.

    My code is:

    import java.sql.*;

    public class hell {
    public static void main(String[] args) {

    try {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
    Connection conn= DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=PersonInfo;user=Sohaib;password=0000;");


    System.out.println("connected");
    }

    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    Here's the Exception

    Exception: Unable to get connect
    com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'Sohaib'.
    and all other supporting errors..
    Unfortunately I am now dead in the water until some kind SqlServer Guru or Jdbc Guru take pity on me and helps me out.

    thanks in advance.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    103
    Rep Power
    3
    Hey dude,

    I haven't tried using JDBC with an actual SQL Server, but I've done it with HSQL in a local project. The way I created the connection is below.

    DriverManager.getConnection("jdbc:hsqldb:databasedbName", "sa", "")

    So yours would look like:
    DriverManager.getConnection("jdbc:sqlserver://localhost:1433/PersonInfo", "Sohaib", "0000");

    Are you positive you have the correct login information? You should be able to check what the login information is if you look at your System Catalog tables.
    http://msdn.microsoft.com/en-us/library/ms178593.aspx
    Last edited by Cameron0960; July 1st, 2013 at 12:37 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0
    Actually the problem got solved! My sql server was having an issue so installed another instance of sql server and everything started working fine!

IMN logo majestic logo threadwatch logo seochat tools logo