Java jTDS 连接问题 Ubuntu 服务器

发布于 2024-10-01 05:39:23 字数 1071 浏览 6 评论 0原文

根据我所读到的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌若浮生 2024-10-08 05:39:23

您似乎正在尝试连接到 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文