先加入sqlite开发库libsqlite3.dylib,
新建或打开数据库,
创建数据表,
插入数据,
查询数据并打印
NSString *sqlQuery = @"SELECT * FROM PERSONINFO"
sqlite3_stmt * statement
if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
char *name = (char*)sqlite3_column_text(statement, 1)
NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name]
int age = sqlite3_column_int(statement, 2)
char *address = (char*)sqlite3_column_text(statement, 3)
NSString *nsAddressStr = [[NSString alloc]initWithUTF8String:address]
NSLog(@"name:%@ age:%d address:%@",nsNameStr,age, nsAddressStr)
}
}
sqlite3_close(db)
这个是onCreate这句话的毛病 它只负责创建数据库。建议是在 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
db.execSQL("create table sunCount(id integer primary key autoincrement,conut integer)")
}
这里面创建 更新数数据库 再创建一张表 就可以了 创建表的方法 和开始一样
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)