贴出实现的原代码
//获取存放的db文件路径(沙盒中)
/*NSArray* arr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * domcatPaths = [arr objectAtIndex:0];
NSString * databasePaths = [domcatPaths stringByAppendingPathComponent:@"ipadTest.db"];
*/
//资源文件中的db文件路径(使用事先制作好的sqlite数据库)
NSString * databasePaths = [[NSBundle mainBundle] pathForResource:@"ipadTest" ofType:@"db"];
//打开数据库连接
sqlite3 * database;
if (sqlite3_open([databasePaths UTF8String], &database) == SQLITE_OK) {
NSLog(@"连接成功!");
}else{
NSLog(@"连接失败!");
}
//查询
NSString *findSql = @"select * from gj";
sqlite3_stmt *stmt;
if (sqlite3_prepare(database, [findSql UTF8String], -1, &stmt, nil)==SQLITE_OK) {
NSLog(@"查询成功!");
}else{
NSLog(@"查询失败!");
}
NSMutableArray *arr = [[NSMutableArray alloc]init];
while (sqlite3_step(stmt)==SQLITE_ROW) {
NSMutableDictionary *obj = [NSMutableDictionary dictionary];
[obj setObject:[[NSString alloc] initWithCString:(char *)sqlite3_column_text(stmt, 0) encoding:NSUTF8StringEncoding] forKey:@"gj"];
[obj setObject:[[NSString alloc] initWithCString:(char *)sqlite3_column_text(stmt, 1) encoding:NSUTF8StringEncoding] forKey:@"dq"];
[obj setObject:[[NSString alloc] initWithCString:(char *)sqlite3_column_text(stmt, 2) encoding:NSUTF8StringEncoding] forKey:@"cjtime"];
[obj setObject:[[NSString alloc] initWithCString:(char *)sqlite3_column_text(stmt, 3) encoding:NSUTF8StringEncoding] forKey:@"fzr"];
[arr addObject:obj];
}
借鉴资料(感谢前辈们的奉献)
添加libsqlite3.0.dylib
http://blog.163.com/wang_1980_ww/blog/static/111141052013415112153216/
libsqlite3.dylib与libsqlite3.0.dylib区别
http://blog.csdn.net/wangqiuyun/article/details/7345743
第三方库FMDB连接sqlite3 数据库
http://www.tuicool.com/articles/Mbaui2
ios简单sqlite使用
http://marshal.easymorse.com/archives/3349
iOS SQLite3初试用
http://mobile.51cto.com/iphone-321932.htm
IOS数据库操作SQLite3使用详解
http://www.cnblogs.com/wengzilin/archive/2012/03/27/2419203.html
iOS 四种保存数据的方式
http://jingyan.baidu.com/article/75ab0bcb06c37fd6874db273.html
ios使用事先制作好的sqlite数据库
http://zhidao.baidu.com/link?url=oPf9MFhErOwTfUpu40y1DuTjrCPLeDYsJQ1P699ZkRTn6G6Ut1Tl-qO094dzfczNoV_XSbtnWREW_GP1GSHTKK