Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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(
    at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(
    at net.sourceforge.jtds.jdbc.TdsCore.login(
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(
    at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(
    at net.sourceforge.jtds.jdbc.Driver.connect(
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at DB.dbConnect(
    at testConnection.main(
share|improve this question
Are you sure the password is correct? Also, what's with the /MnA after localhost:1433? Further,… may be of use. – Simon Righarts Aug 15 '12 at 0:54

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.

share|improve this answer

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");
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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