I am having trouble connecting to my Microsoft SQL Server database through a jTDS connection:

Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433
    /MnA;instance=SQLEXPRESS", "sa","");

SQL Server is enabled, TCP/IP is enabled, Mixed server authentication is enabled.

Any ideas?

java.sql.SQLException: Login failed for user 'sa'.
    at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
    at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
    at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:603)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:345)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at DB.dbConnect(testConnection.java:17)
    at testConnection.main(testConnection.java:7)

You are attempting to pass in a blank password. Odds are the sa account has a password.

You should create a separate account for the application to use instead of using the sa account. Using the sa account is a major security issue.


You are using a blank password.

  1. Use sqljdbc4 jar file
  2. Add this before your connection string:
  3. Use this connection string for your jdbc connection:
    Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433\\SQLEXPRESS;databaseName=xxx","sa","pass");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.