try {
File txt = new File(SDCARD_PATH + "/file//file.txt")// txt文件
br = new BufferedReader(new FileReader(txt))
db = DatabaseManager.getInstance().openDatabase()
db.execSQL("create table if not exists file_table(number integer,"
+ "name integer,"
+ "bh char(50),"
+ "nl char(50),"
+ "jl char(50))")
Cursor cursors = db
.query("file_table", null, null, null, null, null, null)
if (cursors.getCount() != 0) {
br.close()
cursors.close()
return
}
cursors.close()
// 读取直到最后册老一行
String line = ""
if ((line = br.readLine()) != null) {
//毕丛 line = br.readLine()
}
while ((line = br.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line, ",")
ContentValues contentValues = new ContentValues()
int i = 0
while (st.hasMoreTokens()) {
// 每一行州数升的多个字段用TAB隔开表示
String currentString = st.nextToken()
System.out.print(currentString + "\t")
if (i == 0) {
contentValues.put("number", currentString)
}
if (i == 1) {
contentValues.put("name", currentString)
}
if (i == 2) {
contentValues.put("bh", currentString)
}
if (i == 3) {
contentValues.put("nl", currentString)
}
if (i == 4) {
contentValues.put("jl", currentString)
}
++i
Log.v(TAG, currentString)
}
System.out.println()
db.insert("file_table", null, contentValues)
}
} catch (FileNotFoundException e) {
e.printStackTrace()
} catch (IOException e) {
e.printStackTrace()
}finally{
try {
if (br != null) {
br.close()
}
} catch (IOException e) {
e.printStackTrace()
}
}
解决方法:添加事务处理,把5000条插入作为一个事务
dataBase.beginTransaction() //手动设置开始事务
//数扒羡据插入 *** 作循环
dataBase.setTransactionSuccessful() //设置事务处理成功,不设置会自动回滚不提交
dataBase.endTransaction() //处理完成
将数据库「倒出来」:
sqlite3 film.db ".dump" >output.sql
利用输出的资料,建立一个一模一样的数据库(加上以上指令,就是标准的SQL数据库
备份了):
sqlite3 film.db <output.sql
在春巧拍大量插入资料时,你可能会需要先打这个指令:
begin
插入完资料后要记得打这个指令,资料才会宽郑写进数据库中:
commit
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)