IOS reads data from the database through a third-party fmdb

Source: Internet
Author: User

Step 1: add the fmdb class library to the project in the new project,

Step 2: Put the. DB database in the following directory:

/Users/Apple/library/Application Support/iPhone simulator/6.1/applications/06a47f8b-23ea-48d5-80a5-54cf37d0d8b8/documents/tcfexam. DB

Database


Step 3: Enter the followingCode:

/// Textoneviewcontroller. M // tcfexamtextone /// created by Apple on 13-7-13. // copyright (c) 2013 apple. all rights reserved. // # import "textoneviewcontroller. H "# import" fmdatabase. H "# import" fmresultset. H "@ interface textoneviewcontroller () @ end @ implementation textoneviewcontroller-(ID) initwithnibname :( nsstring *) nibnameornil bundle :( nsbundle *) {self = [Super initwithnibname: nibna Meornil Bundle: nibbundleornil]; If (Self) {// custom initialization} return self;}-(void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view from Its nib .} -(void) didreceivememorywarning {[Super didreceivemorywarning]; // dispose of any resources that can be recreated .} -(ibaction) didsearch :( ID) sender {nsarray * paths = nssearchpathfordirectoriesindomains (nsdoc Umentdirectory, nsuserdomainmask, yes); nsstring * documentpath = [paths objectatindex: 0]; nsstring * dbpath = [documentpath stringbyappendingpathcomponent: @ "tcfexam. DB "]; fmdatabase * database = [fmdatabase databasewithpath: dbpath]; If (! [Database open]) {return;} // query the allthequstions fmresultset * resultset = [database executequery: @ "select * From allthequstions"]; // read data row by row while ([resultset next]) {// obtain the data nsstring * History = [resultset stringforcolumn: @ "History"]; nsstring * question = [resultset stringforcolumn: @ "Question"]; nslog (@ "History: % @, question: % @", history, question );} [database close];} @ end

Step 4: The output result is as follows:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.