Take the 2-minute tour ×
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. It's 100% free, no registration required.

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)
share|improve this question
    
Are you sure the password is correct? Also, what's with the /MnA after localhost:1433? Further, blogs.msdn.com/b/brian_swan/archive/2011/03/02/… may be of use. –  Simon Righarts Aug 15 '12 at 0:54

2 Answers 2

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:
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  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

 
discard

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.