服务器名称包含反斜杠时使用JDBC(localhost \TESTDATA) [英] Using JDBC when server name contains a backslash (localhost\TESTDATA)
问题描述
感谢您花时间阅读本文。我完全被这可能是一件简单的事情所困扰。我正在尝试连接到我的SQL数据库,以下方法可以正常工作:
thanks for taking the time to read this. I'm completely stumped by what is probably a simple thing. I am trying to make a connection to my SQL database, the following tends to work:
String url = "jdbc:jtds:sqlserver://10.0.100.200;DatabaseName=master;user=sa;password=";
但是当我的名字包含反斜杠时,例如localhost \TESTDATA我似乎无法得到它正在工作,我正在
However when my name contains a backslash, for example "localhost\TESTDATA I cannot seem to get it working, I am getting
java.sql.SQLException:未知服务器主机名'localhost \TESTDATA'。
"java.sql.SQLException: Unknown server host name 'localhost\TESTDATA'."
当我使用以下内容时:
String url = "jdbc:jtds:sqlserver://localhost\\TESTDATA;DatabaseName=master;user=sa;password=";
谢谢
推荐答案
jtds驱动程序与ms驱动程序的语法不同。您应该将实例名称作为属性发送,例如:
The jtds driver does not have the same syntax as the ms driver. You should send the instance name as a property, i.e. like this:
"jdbc:jtds:sqlserver://localhost/master;instance=TESTDATA;..."
另请注意,数据库名称是以 / master
而非作为祝你好运!
Also notice that the database name is sent as /master
instead of as a property. Good luck!
这篇关于服务器名称包含反斜杠时使用JDBC(localhost \TESTDATA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!