简体   繁体   English

无法使用jdbc连接到SQL Server 2008

[英]Unable to connect to sql server 2008 with jdbc

I'm trying to connect to a sql server with JDBC in java. 我正在尝试使用Java中的JDBC连接到sql服务器。

My server uses a windows authentication. 我的服务器使用Windows身份验证。

I use this code: 我使用以下代码:

String url = "jdbc:sqlserver://MYPC\\MYSERVER;databaseName=MYDB;integratedSecurity=true";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(url);

In my classpath i have the file: jtds-1.3.1.jar and sqljdbc4.jar 在我的类路径中,我有以下文件:jtds-1.3.1.jar和sqljdbc4.jar

And i have a VM argument: 而且我有一个VM参数:

-Djava.library.path="SQLPATH\jtds\x64\SSO"

When i run the code, i have this exception: 当我运行代码时,我有以下异常:

com.microsoft.sqlserver.jdbc.SQLServerException: Unable to connect to the host MYPC

Do you know what is wrong? 你知道出什么事了吗

The URL syntax is jdbc:sqlserver://[serverName[\\instanceName][:portNumber]][;property=value[;property=value]] URL语法为jdbc:sqlserver:// [serverName [\\ instanceName] [:portNumber]] [; property = value [; property = value]]

Did you try to ping your host using ping command ? 您是否尝试使用ping命令ping主机? Or try with IP address. 或尝试使用IP地址。

If //MYPC\\\\MYSERVER is a network path, I'd imagine it needs to look like this: 如果//MYPC\\\\MYSERVER是网络路径,我想它需要看起来像这样:

\\MYPC\\MYSERVER

Of course, if the SQL Server 2008 instance is setup as the default instance, the \\\\MYSERVER portion isn't necessary. 当然,如果将SQL Server 2008实例设置为默认实例,则\\\\MYSERVER部分不是必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM