Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SQLServer的Hibernate配置-驱动程序类_Java_Sql Server_Hibernate_Jdbc_Driver - Fatal编程技术网

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

Java SQLServer的Hibernate配置-驱动程序类,java,sql-server,hibernate,jdbc,driver,Java,Sql Server,Hibernate,Jdbc,Driver,我正在尝试使用SQLServerDB配置hibernate 配置: public static SessionFactory getSessionFactory() { try { if (null==sessionFactory) { Properties hb_props = new Properties(); hb_props.put("hibernate.dialect", "org.hibernate.dialec

我正在尝试使用SQLServerDB配置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");

这篇来自JBoss的文章使用了
\uuu
而不是

我想你在帖子中编辑了服务器URL和数据库名称?如果我没有编辑,那会很有趣=p,是的,它们是出于安全目的编辑的,也许我有点偏执..这是正确的做法,我只是确定它是有意的是的,我很确定连接字符串是正确的,但是现在我想,如果数据库名有一个特定的属性(我猜是这样的),那么我可能不必把数据库名也放在hibernate.connection.url属性中。。去搜索发现问题:我写了:hb_props.put(“hibernate.connection.driver.class”,“com.microsoft.sqlserver.jdbc.SQLServerDriver”);而不是:hb_props.put(“hibernate.connection.driver_class”,“com.microsoft.sqlserver.jdbc.SQLServerDriver”);这就是答案;),我还必须指出,我声明属性“hibernate.connection.url”而不是“jdbc:sqlserver://serverurl//dbname正确的字符串类似于:“jdbc:sqlserver://serverurl;databaseName=dbname”。在许多帖子中,我看到在hibernate配置xml中,它是以第一种方式编写的,我想知道它在运行时传递时是否有所不同