【问题标题】:org.hibernate.exception.JDBCConnectionException: Error calling Driver#connectorg.hibernate.exception.JDBCConnectionException:调用驱动程序时出错#connect
【发布时间】:2014-03-20 16:48:33
【问题描述】:

我正在尝试解决一个问题,但我无法做到这一点。我创建了一个 JFrame 来输入一些数据库信息(IP、名称、用户、密码)。

在此之后,我删除了 hibernate cfg 文件,并在 HibernatUtil 类中使用 .setProperty 自己插入了配置。我正在使用与我删除的 cfg 文件相同的配置,它可以正常工作,但现在使用 setProperty 却不行。

Netbeans 显示 Hibernate 错误:

org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect

还有一个 SQL 错误:

java.sql.SQLException: The syntax of the connection URL 'jdbc:jtds:sybase//ip/nomeDoBanco' is invalid

更新

我的 HibernateUtil 类:

Configuration cfg = new Configuration();
        cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.SybaseDialect");
        cfg.setProperty("hibernate.connection.driver_class", "com.sybase.jdbc4.jdbc.SybDriver");
        cfg.setProperty("hibernate.connection.url", url);
        cfg.setProperty("hibernate.connection.username", username);
        cfg.setProperty("hibernate.connection.password", password);
        cfg.setProperty("hibernate.show_sql", "true");
        cfg.setProperty("hibernate.format_sql", "true");
        cfg.addAnnotatedClass(Node.class);
        cfg.addAnnotatedClass(Fault.class);
        factory = cfg.buildSessionFactory();

我正在使用这些罐子:

【问题讨论】:

    标签: java swing hibernate


    【解决方案1】:

    您的司机似乎不对..

    参考这个...

    #hibernate.dialect org.hibernate.dialect.SybaseDialect
    #hibernate.connection.driver_class com.sybase.jdbc2.jdbc.SybDriver
    #hibernate.connection.username sa
    #hibernate.connection.password sasasa
    #hibernate.connection.url jdbc:sybase:Tds:co3061835-a:5000/tempdb
    

    您应该使用 SybDriver..

    把你的网址改成

    jdbc:sybase:Tds:ip:5000/nomeDoBanco
    

    【讨论】:

    • 我会试试这个,但只有一条评论,是 jdbc:sybase:Tds 还是 jdbc:sybase:jtds ?
    • 我觉得你的 url 应该没问题.. 试试改驱动名
    • Nikhil,我改了方言和driver_class,请看更新。
    • 这应该是你的 url jdbc:sybase:Tds:localhost:5000/dbtest 使用 tds
    【解决方案2】:

    你确定这条线是正确的吗?

    cfg.setProperty("hibernate.connection.driver_class", "net.sourceforge.jtds.jdbc.Driver");
    

    在我看来,您正在设置一个您的环境不知道的驱动程序类。

    【讨论】:

      猜你喜欢
      • 2014-11-23
      • 1970-01-01
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      相关资源
      最近更新 更多