MS SQL Server and JDBC: closed connection

前端 未结 3 1119
南笙
南笙 2021-01-17 23:25

Im getting

I/O Error: DB server closed connection.

while connecting to MS SQL server 2008 from java code .

相关标签:
3条回答
  • 2021-01-17 23:27

    Your Connection String and authentication have errors. if it is mix mode don't use SQL authentication

    Try this

    PC Name : janaka-pc SQL User Name : sa SQL Password
    : 1234 Database : Janak_DB

    Code for sql Conncetion in JDBC

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection conn = DriverManager.getConnection("jdbc:sqlserver://janaka-PC;user=sa;password=1234;database=Janak_DB");

    0 讨论(0)
  • 2021-01-17 23:47

    You have problems in your connection strings

    For jTDS:

    jdbc:jtds:sqlserver://machineName:1433;databaseName=DB;useNTLMv2=tru‌​e;domain=workgroup

    You may read http://jtds.sourceforge.net/faq.html#windowsAuth for the required Single-Sign-On library for NTLM to work.

    "integratedSecurity=true" that you supplied for jdts is valid when using the JDBC driver

    jdbc:sqlserver://machine:1433;instance=SQLEXPRESS;databaseName=db;integratedSecurity=true

    0 讨论(0)
  • 2021-01-17 23:53

    You have an authentication error in on the MS SQL side.

    If you're not in control of how to adquire the connection (ie, you're using a Datasource or a Connection Pool), the connection URL must contain the login and password to be used, like:

    jdbc:sqlserver://machine:1433;instance=SQLEXPRESS;databaseName=db;user=USERNAME;password=PASSWORD";
    

    If the application is running on a Windows machine and you want to use the credentials of the logged user, then you can specify the domain parameter with or without useNTLMv2.

    Finally, if you are on a windows machine but you want to authenticate the user against a domain, then you must supply the username, password and domain parameters. You can read all about it in the jtds FAQ, specially the URL Format section.

    0 讨论(0)
提交回复
热议问题