环境 :JDK1.6
JAVA APPLICATION 开发
SQLite3
问题: 在用JAVA调用“DELETE FROM 表名 ”时数据库文件就出错,出错信息“database disk image is malformed”。
请高手解答:
1、是何原因造成这个问题?
2、怎么解决 这个问题。
------解决方案--------------------
检查 磁盘空间、确定数据库文件是否损坏(写入数据过程中突然掉电、非正常退出程序)
------解决方案--------------------
试试能否导出数据库:
首先导出数据
sqlite3 tt
sqlite>.output old.sql
sqlite>.dump
sqlite>.quit
再倒入到一个新库中
sqlite3 newtt
sqlite>.read old.sql
sqlite>.quit
------解决方案--------------------
你直接DROP TABLE TT,再建立1个不行?
------解决方案--------------------
sqlite faq:
(21) What is an SQLITE_CORRUPT error? What does it mean for the database to be "malformed"? Why am I getting this error?
An SQLITE_CORRUPT error is returned when SQLite detects an error in the structure, format, or other control elements of the database file.
SQLite does not corrupt database files, except in the case of very rare bugs (see DatabaseCorruption) and even then the bugs are normally difficult to reproduce. Even if your application crashes in the middle of an update, your database is safe. The database is safe even if your OS crashes or takes a power loss. The crash-resistance of SQLite has been extensively studied and tested and is attested by years of real-world experience by millions of users."
That said, there are a number of things that external programs or bugs in your hardware or OS can do to corrupt a database file. Details can be found in the discussions on the atomic commit and locking support in SQLite as well as in the mailing list archives.
Your can use PRAGMA integrity_check to do a thorough but time intensive test of the database integrity.
Your can use PRAGMA quick_check to do a faster but less thorough test of the database integrity.
Depending how badly your database is corrupted, you may be able to recover some of the data by using the CLI to dump the schema and contents to a file and then recreate. Unfortunately, once humpty-dumpty falls off the wall, it is generally not possible to put him back together again.