java - 使用 java 访问 SQLite 数据库

标签 java spring hibernate sqlite

我需要使用 java 访问 SQLite 数据库。我收到此错误:

Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.SQLiteDialect] as strategy [org.hibernate.dialect.Dialect]

每当我想创建我的 sessionFactory bean 时。

数据库属性:

db.driver.class=org.sqlite.JDBC
db.server.url=jdbc:sqlite:"G:\\Ausbildung\\username\\Database\\informations.db"
db.username=
db.password=

db.hibernate.dialect=org.hibernate.dialect.SQLiteDialect
db.hibernate.schema=DATA
db.hibernate.hbm2ddl.auto=update

xml 文件中的 bean 声明:

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
        lazy-init="true">
        <property name="driverClassName">
            <value>${db.driver.class}</value>
        </property>
        <property name="url">
            <value>${db.server.url}</value>
        </property>
        <property name="username">
            <value>${db.username}</value>
        </property>
        <property name="password">
            <value>${db.password}</value>
        </property>
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"
        lazy-init="true">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan">
            <list>
                <value>com.mainfirst.bloomberg.invoice.report.model</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${db.hibernate.dialect}</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.default_schema">${db.hibernate.schema}</prop>
                <prop key="hibernate.hbm2ddl.auto">${db.hibernate.hbm2ddl.auto}</prop>
                <prop key="hibernate.connection.CharSet">utf8</prop>
                <prop key="hibernate.connection.characterEncoding">utf8</prop>
                <prop key="hibernate.connection.useUnicode">true</prop>
            </props>
        </property>
    </bean>

我找不到我犯的错误。此构造适用于 Apache Derby。我只更改了 hibernate.dialect 和 driver.class 以及 server.url。

如果我删除 db.server.url 中的“”,则会收到错误

Caused by: java.lang.AbstractMethodError: org.sqlite.Conn.isValid(I)Z

提前致谢

最佳答案

修复了使用此 SQLite 方言进行 hibernate 的问题:

<groupId>com.enigmabridge</groupId>
<artifactId>hibernate4-sqlite-dialect </artifactId>
<version>0.1.0</version>

关于java - 使用 java 访问 SQLite 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40783163/

相关文章:

java - freemarker 将 ${..} 显示为 html 而不是字符串

spring - 在 FeignClient 中处理 HTTP 重定向

java - 将spring持久化存储库注入(inject)到服务层

java - 必须至少存在一个 JPA 元模型!但它是生成的吗?

spring - 实体类何时增强,用于什么? jpa, Spring , hibernate ,javassist

java - 使用 hibernate 条件左连接

java - 如何使用hibernate更新数据库?

java - 通过 Java 在 bash 文件中执行 NS 包

Java - 使用列表迭代器返回对链表中特定位置的引用

java - Thymeleaf 和带指纹的静态资源