【问题标题】:SQL Server conecction with jdbc eclipseSQL Server 与 jdbc eclipse 的连接
【发布时间】:2019-04-14 14:00:29
【问题描述】:

我有以下代码可以连接到我在 SQL Server 中的数据库:

public static void main (String [] args) {
    try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        String url = "jdbc:sqlserver://DESKTOP-G8057U8\\SQLEXPRESS:1433;databaseName=Vaporizadores;integratedSecurity=true;";
        DBConection=DriverManager.getConnection(url);
        DBStatement = DBConection.createStatement();
        System.out.println("Conexion exitosa");
    }catch(ClassNotFoundException | SQLException e) {
        System.out.println("Conexion fallida");
    }
}

当我运行它时,我得到“Conexion fallida”,这意味着捕获了一个异常。我尝试了不同的网址,但仍然无法连接到我的数据库。我对jdbc和sql server知之甚少,所以可能是个愚蠢的错误。

【问题讨论】:

  • 做一个,catch(ClassNotFoundException | SQLException e) { System.out.println(e); } 并给出结果...
  • 不要同时指定端口 (1433) 和实例名称 (SQLEXPRESS)。它们是相互排斥的。删除端口号。
  • @dilanSachi 更好的是:catch(ClassNotFoundException | SQLException e) { e.printStackTrace(System.out); }
  • integratedSecurity=true 需要 PATH 中的 .dll 文件。有吗?
  • @Andreas thanx 给小费

标签: java sql-server eclipse jdbc


【解决方案1】:

它是这样工作的:
字符串 url = "jdbc:sqlserver://DESKTOP-G8057U8;databaseName=Vaporizadores;integratedSecurity=true;"; 我将 sqljdbc_auth.dll 添加到 Java bin 文件夹中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    • 2017-10-17
    • 2014-12-01
    • 2019-01-03
    • 1970-01-01
    相关资源
    最近更新 更多