Java org.hibernate.exception.JDBCConnectionException:调用驱动程序时出错#connect

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22539800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:21:46  来源:igfitidea点击:

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

javaswinghibernate

提问by Murilo

I am trying to fix an issue but I couldnt do this. I created a JFrame to input some database information (IP, Name, User, Password).

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

After this, I removed the hibernate cfg file, and in HibernatUtil class I inserted the configs by myself using .setProperty. I am using the same configs of the cfg file that I removed, which was working but now using setProperty it isnt.

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

Netbeans is showing an Hibernate error:

Netbeans 显示休眠错误:

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

And a SQL Error:

和一个 SQL 错误:

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

UPDATE

更新

My HibernateUtil class:

我的 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();

I am using these jars:

我正在使用这些罐子:

enter image description here

在此处输入图片说明

采纳答案by Nikhil

Your driver does not seem to be right..

你的司机好像不对..

Refer this...

参考这个...

#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

you should be using the SybDriver..

你应该使用 SybDriver ..

Change your url to

将您的网址更改为

jdbc:sybase:Tds:ip:5000/nomeDoBanco

回答by PurplePanda

Are you sure this line is correct ?

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

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

It seems to me that you are setting a driver class not known by your environnement.

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