gpt4 book ai didi

java - 使用 hibernate 和 ms sql server 驱动程序

转载 作者:行者123 更新时间:2023-12-01 14:08:15 24 4
gpt4 key购买 nike

Microsoft 不向中央 Maven 存储库提供 jdbc jar。它需要手动注册驱动程序。但我做错了什么。我看到了相同的异常跟踪:

Initial SessionFactory creation failed.org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver "com.microsoft.sqlserver.jdbc.SQLServerDriver" class not found
Exception in thread "main" java.lang.ExceptionInInitializerError
at logic.HibernateUtil.buildSessionFactory(HibernateUtil.java:22)
at logic.HibernateUtil.<clinit>(HibernateUtil.java:8)
at logic.Main.main(Main.java:12)
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver "com.microsoft.sqlserver.jdbc.SQLServerDriver" class not found
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:107)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2277)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2273)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1742)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1782)
at logic.HibernateUtil.buildSessionFactory(HibernateUtil.java:17)
... 2 more
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class ["com.microsoft.sqlserver.jdbc.SQLServerDriver"]
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:104)
... 16 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : "com.microsoft.sqlserver.jdbc.SQLServerDriver"
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)
... 17 more

我使用STS(eclipse产品)在 Maven 依赖项中: enter image description here

我做错了什么?

最佳答案

如果您使用 JRE 版本 6.0 或 7.0,则使用 sqljdbc4.jar 文件。如果JRE版本是5.0,则使用sqljdbc.jar文件。

这些jar文件可以从here下载

此外,您还可以从 here 更清楚地了解 JDBC 驱动程序的系统要求。

关于java - 使用 hibernate 和 ms sql server 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18737565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com