gpt4 book ai didi

java - SQLServer 的 Hibernate 配置 - 驱动程序类

转载 作者:行者123 更新时间:2023-11-30 09:24:48 27 4
gpt4 key购买 nike

我正在尝试使用 SQLServer 数据库配置 hibernate 。

配置:

public static SessionFactory getSessionFactory() {
try {
if (null==sessionFactory) {
Properties hb_props = new Properties();
hb_props.put("hibernate.dialect", "org.hibernate.dialect.SQLServer2005Dialect");
hb_props.put("hibernate.connection.driver.class", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
hb_props.put("hibernate.connection.username", "someusername");
hb_props.put("hibernate.connection.password", "somepassword");
hb_props.put("hibernate.connection.url", "jdbc:sqlserver://serverurl//dbname");
Configuration configuration = new Configuration();
configuration.setProperties(hb_props);
sessionFactory = configuration.addAnnotatedClass(Test.class).buildSessionFactory();
}
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
return sessionFactory;
}

我收到以下错误:

[main] WARN org.hibernate.connection.DriverManagerConnectionProvider - no JDBC Driver class was specified by property hibernate.connection.driver_class
[main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: null at URL: jdbc:sqlserver://serverurl//dbname
[main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=someusername, password=****, driver.class=com.microsoft.sqlserver.jdbc.SQLServerDriver}
[main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://serverurl//dbname
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:113)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
.....

我正在使用 sqljdbc-1.2.jar 并且驱动程序类拼写正确,无法确定缺陷在哪里..

最佳答案

尝试改变这个:

hb_props.put("hibernate.connection.driver.class",
"com.microsoft.sqlserver.jdbc.SQLServerDriver");

对此:

hb_props.put("hibernate.connection.driver_class",
"com.microsoft.sqlserver.jdbc.SQLServerDriver");

configuration guide来自 JBoss 使用 _ 而不是 .

关于java - SQLServer 的 Hibernate 配置 - 驱动程序类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15519621/

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