關於sqlite資料庫的問題

2021-12-30 09:10:24 字數 825 閱讀 9642

關於sqlite資料庫的問題

首先初始化乙個資料庫,用for迴圈插入記錄。

databasehelper dbhelper = new databasehelper(chushihua.this,

"test.db");

sqlitedatabase db = dbhelper.getwritabledatabase();

db.execsql("create table if not exists teacher(te_id integer primary key autoincrement,kecheng varchar(10)," +

"dijijie integer,xingqi integer ,jiaoshi varchar(10),jiaoxuelou varchar(10),zhuanye varchar(10),beizhu varchar(20))");

contentvalues values = new contentvalues();

values.put("xingqi", 1);

db.insert("teacher", null, values);

本來存在 if not exists teacher這句話以為下次不會再次初始化,可是只要啟動一次,資料庫就初始化一次,記錄越來越多,怎麼解決呢?

不知道你的初始化資料庫操作在那裡了。初始化資料庫的操作你可以放在繼承的 sqliteopenhelper 的類裡,覆蓋掉

@override

public void oncreate(sqlitedatabase p_database)

方法,該方法會在你第一次使用資料庫時執行,且只執行一次。

關於Sqlite資料庫Update語句的一點介紹

sqlite資料庫中的update語句,你能了解多少呢?因為這種微型資料庫用到的語句非常少,所以可能我們不會經常的用到。但要想真正的玩轉sqlite這種微型資料庫,掌握這些語句的用法是非常重要的。本文我們就來介紹一下update語句的使用。1.典型的update 支援 update t1 set c...

關於SQLite資料庫的那點事

1.sqlite屬於輕型的資料庫,事物有四種屬性,原子性,一致性,隔離性,永續性。2.在進行建立資料庫時候採用繼承sqliteopenhelper,然後實現其中的方法,在databasehelper方法中factory方法可以為null 3.在oncreate方法中執行sql語句建立資料庫。4.資料...

Qt使用sqlite資料庫的問題

之前使用資料庫用的都是mysql,覺得挺方便的,但最近做的程式要在linux開發板上跑,就使用了qt自帶的輕量級資料庫sqlite,但使用過程中遇到了一些問題 標頭檔案 include qsqldatabase db public explicit widget qwidget parent 0 w...