I have a local MS SQL Server and I am trying to connect to it using JTDS in java. Here is the connection string:
我有一个本地MS SQL Server,我试图在java中使用JTDS连接到它。这是连接字符串:
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/stock","sa","password");
And the server properties:
name: USER-PC\SQLEXPRESS
root directory: c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL
和服务器属性:名称:USER-PC \ SQLEXPRESS根目录:c:\ Program Files \ Microsoft SQL Server \ MSSQL11.SQLEXPRESS \ MSSQL
I am getting a Exception in thread "main" java.sql.SQLException: Network error IOException: Connection refused: connect
error.
我在线程“main”java.sql.SQLException中得到一个异常:网络错误IOException:连接被拒绝:连接错误。
How can I remedy this?
我该如何解决这个问题?
3 个解决方案
#1
11
Check the following:
检查以下内容:
- You have enabled mixed mode security, i.e. so you can connect with username/password (rather than using Windows authentication)
- The TCP/IP protocol is enabled. Open SQL Server Configuration Manager, then in SQL Server Network config select Protocols and Enable TCP/IP.
-
Try passing just one String to getConnection using this format:
尝试使用以下格式将一个String传递给getConnection:
DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/stock;instance=SQLEXPRESS;user=sa;password=password")
-
If you are using this format (naming the instance) then the SQL Server Browser service needs to be running (in Services). If this is greyed out then the Service is probably disabled, so enable it and then start it.
如果您使用此格式(命名实例),则需要运行SQL Server Browser服务(在“服务”中)。如果显示为灰色,则可能禁用了服务,因此启用它然后启动它。
您已启用混合模式安全性,即您可以使用用户名/密码连接(而不是使用Windows身份验证)
TCP / IP协议已启用。打开SQL Server配置管理器,然后在SQL Server网络配置中选择协议并启用TCP / IP。
#2
0
Port 1433 is the port used by the default instance. You're using SQLEXPRESS, which is a named instance. Your connection string should include something like:
端口1433是默认实例使用的端口。您正在使用SQLEXPRESS,它是一个命名实例。您的连接字符串应包含以下内容:
sqlserver://localhost\SQLEXPRESS
#3
0
SQL Server Browser service is disable by default. If you're developing .Net app, you do not need to start SQLBrowser, but if you're using JTDS in java, you will need it started.
默认情况下禁用SQL Server Browser服务。如果您正在开发.Net应用程序,则不需要启动SQLBrowser,但如果您在java中使用JTDS,则需要启动它。
#1
11
Check the following:
检查以下内容:
- You have enabled mixed mode security, i.e. so you can connect with username/password (rather than using Windows authentication)
- The TCP/IP protocol is enabled. Open SQL Server Configuration Manager, then in SQL Server Network config select Protocols and Enable TCP/IP.
-
Try passing just one String to getConnection using this format:
尝试使用以下格式将一个String传递给getConnection:
DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/stock;instance=SQLEXPRESS;user=sa;password=password")
-
If you are using this format (naming the instance) then the SQL Server Browser service needs to be running (in Services). If this is greyed out then the Service is probably disabled, so enable it and then start it.
如果您使用此格式(命名实例),则需要运行SQL Server Browser服务(在“服务”中)。如果显示为灰色,则可能禁用了服务,因此启用它然后启动它。
您已启用混合模式安全性,即您可以使用用户名/密码连接(而不是使用Windows身份验证)
TCP / IP协议已启用。打开SQL Server配置管理器,然后在SQL Server网络配置中选择协议并启用TCP / IP。
#2
0
Port 1433 is the port used by the default instance. You're using SQLEXPRESS, which is a named instance. Your connection string should include something like:
端口1433是默认实例使用的端口。您正在使用SQLEXPRESS,它是一个命名实例。您的连接字符串应包含以下内容:
sqlserver://localhost\SQLEXPRESS
#3
0
SQL Server Browser service is disable by default. If you're developing .Net app, you do not need to start SQLBrowser, but if you're using JTDS in java, you will need it started.
默认情况下禁用SQL Server Browser服务。如果您正在开发.Net应用程序,则不需要启动SQLBrowser,但如果您在java中使用JTDS,则需要启动它。