springboot sqlite 的疑难解决:The database disk image is malformed
程序员文章站
2024-02-12 13:27:10
...
通常情况下springboot中的配置如下:
spring.datasource.driver-class-name=org.sqlite.JDBC
spring.datasource.jdbc-url=jdbc:sqlite::resource:db/tcl.db
spring.datasource.username=
spring.datasource.password=
多半会出现以下错误:
org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL
Caused by: org.sqlite.SQLiteException: [SQLITE_CORRUPT] The database disk image is malformed (database disk image is malformed)
at org.sqlite.core.DB.newSQLException(DB.java:909) ~[sqlite-jdbc-3.23.1.jar:na]
at org.sqlite.core.DB.newSQLException(DB.java:921) ~[sqlite-jdbc-3.23.1.jar:na]
at org.sqlite.core.DB.throwex(DB.java:886) ~[sqlite-jdbc-3.23.1.jar:na]
at org.sqlite.core.NativeDB.prepare_utf8(Native Method) ~[sqlite-jdbc-3.23.1.jar:na]
at org.sqlite.core.NativeDB.prepare(NativeDB.java:127) ~[sqlite-jdbc-3.23.1.jar:na]
at org.sqlite.core.DB.prepare(DB.java:227) ~[sqlite-jdbc-3.23.1.jar:na]
at org.sqlite.core.CorePreparedStatement.<init>(CorePreparedStatement.java:45) ~[sqlite-jdbc-3.23.1.jar:na]
at org.sqlite.jdbc3.JDBC3PreparedStatement.<init>(JDBC3PreparedStatement.java:30) ~[sqlite-jdbc-3.23.1.jar:na]
at org.sqlite.jdbc4.JDBC4PreparedStatement.<init>(JDBC4PreparedStatement.java:19) ~[sqlite-jdbc-3.23.1.jar:na]
at org.sqlite.jdbc4.JDBC4Connection.prepareStatement(JDBC4Connection.java:48) ~[sqlite-jdbc-3.23.1.jar:na]
at org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:263) ~[sqlite-jdbc-3.23.1.jar:na]
at org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:235) ~[sqlite-jdbc-3.23.1.jar:na]
at com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:311) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariProxyConnection.prepareStatement(HikariProxyConnection.java) ~[HikariCP-3.2.0.jar:na]
at org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement(JdbcTemplate.java:1555) ~[spring-jdbc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:614) ~[spring-jdbc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
... 85 common frames omitted
要修改成
# jdbctemplate访问
spring.datasource.jdbc-url=jdbc:sqlite:d:/rpos/tcl.db
或
#mybatis等其他ORM的数据源
spring.datasource.url=jdbc:sqlite:d:/rpos/tcl.db
为什么?为什么?!!!
源码中的tcl.db内容是不会随着增删改查发生变化,而target目录中的tcl.db的内容会随着增删改查不断发生变化。如果现在执行maven的clean操作,那么增删改查后的tcl.db就会被clean掉,那这问题不大了。
所以建议将spring.datasource.jdbc-url=jdbc:sqlite:d:/exmn/tcl.db 设置成固定路径。避免出现文件破坏,如下org.sqlite.SQLiteException: [SQLITE_CORRUPT] The database disk image is malformed (database disk image is malformed)。
下一篇: 测试速度