gpt4 book ai didi

java - SQL Server 连接被拒绝且 jTDS 驱动程序无法工作

转载 作者:行者123 更新时间:2023-11-30 07:27:20 33 4
gpt4 key购买 nike

我正在尝试连接到本地 SQL Server 数据库。数据库名称是 MDB,这些是我使用的凭据。也尝试过 user="User" 但没有成功。
我的库中有以下 jar:jtds-1.3.1.jar
我使用的SQL Server版本是2012。

String url = "jdbc:jtds:sqlserver://localhost:1344/MDB;instance=sqlserver;useNTLMv2=true;";
String user = "User-PC\\User";
String pass = "";

我也尝试过使用 localhost:1099 但没有成功。

try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
}
catch (ClassNotFoundException e){
e.printStackTrace();
System.out.println("1st error");
}
try
{
Connection con = DriverManager.getConnection( dbUrl, dbUser, dbPwd );
System.out.println("Worked");
} catch (SQLException e){
e.printStackTrace();
System.out.println("Driver error");
}

我已将 JTDS jar 放入我的外部库中。我得到的错误如下:

java.sql.SQLException: Network error IOException: Connection refused: connect at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:436) at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:215) at Main.main(Main.java:33) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288) at net.sourceforge.jtds.jdbc.SharedSocket.(SharedSocket.java:251) at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:331) ... 9 more

来自 SQL 的信息:登录名:用户-PC\用户服务器名称:USER-PC

最佳答案

您需要确保在 SQL Server 配置中启用 TCP/IP 端口,并且 SQL Server Browser 服务也在运行。

关于java - SQL Server 连接被拒绝且 jTDS 驱动程序无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36645843/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com