Java jTDS 连接问题 Ubuntu 服务器
根据我所读到的 jTDS 的正确连接字符串是:
jdbc:jtds:<server_type>://<server>[:<port>][/<database>]
我认为问题在于服务器名称。服务器名称的格式如下
servername\adhoc
每当我尝试连接时都会抛出 SQLException 并说“未知的服务器主机名”
这是我的问题,还是我还需要研究其他问题......?
import java.sql.*;
public class Main {
// The JDBC Connector Class.
private static final String MSdbClassName = "net.sourceforge.jtds.jdbc.Driver";
private static final String MSHOST = "servername\\adhoc"; //cascrmeufosqlp1\adhoc
private static final String MSDATABASE = "tier2";
private static final String MSUSER = "feed_****2";
private static final String MSPASSWORD = "*******0";
public static void main(String[] args) throws ClassNotFoundException,SQLException
{
Class.forName(MSdbClassName);
String url2 = "jdbc:jtds:sqlserver://" + MSHOST + ":1433/" + MSDATABASE;
Connection c2 = java.sql.DriverManager.getConnection( url2, MSUSER, MSPASSWORD );
System.out.println("MS SQL works...");
c2.close();
}
}
From what I have read the correct connection string for a jTDS is:
jdbc:jtds:<server_type>://<server>[:<port>][/<database>]
I believe the issue is the server name. The server name is formatted like this
servername\adhoc
An SQLException gets thrown anytime I try to connect saying "unknown server host name"
Is that my issue, or is there something else I need to look into as well...?
import java.sql.*;
public class Main {
// The JDBC Connector Class.
private static final String MSdbClassName = "net.sourceforge.jtds.jdbc.Driver";
private static final String MSHOST = "servername\\adhoc"; //cascrmeufosqlp1\adhoc
private static final String MSDATABASE = "tier2";
private static final String MSUSER = "feed_****2";
private static final String MSPASSWORD = "*******0";
public static void main(String[] args) throws ClassNotFoundException,SQLException
{
Class.forName(MSdbClassName);
String url2 = "jdbc:jtds:sqlserver://" + MSHOST + ":1433/" + MSDATABASE;
Connection c2 = java.sql.DriverManager.getConnection( url2, MSUSER, MSPASSWORD );
System.out.println("MS SQL works...");
c2.close();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎正在尝试连接到 sql server 的“命名实例”。您需要在 url 中使用“instance”属性。类似这样的方法可能有效:
jdbc:jtds:sqlserver://servername:1433/dbName;appName=MyAPP;instance=instanceName
请参阅 jTDS 常见问题解答以获取此处的更多信息:http://jtds.sourceforge.net/faq.html
It looks like you are trying to connect to a "named instance" of sql server. You will need to use the "instance" property in the url. Something like this might work:
jdbc:jtds:sqlserver://servername:1433/dbName;appName=MyAPP;instance=instanceName
See the jTDS faq for more information found here: http://jtds.sourceforge.net/faq.html