retrieve data from database and implement it in table view
<p>I am new in iphone programming. I am working for small iphone application in which I have put three textfield for name, contact, email id and saving all this data in database. Now I want to retrieve the data from database and display it in table-view. How can I do this implementation. Please help me.
Following is the code for saving data in database.</p>

<pre><code>-(void)viewWillAppear:(BOOL)animated
{
    [self createEditableCopyOfDatabaseIfNeeded];
    [self initializeDatabase];

}

- (void)createEditableCopyOfDatabaseIfNeeded 
{
    //NSLog(@"Creating editable copy of database");
    // First, test for existence.
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"finaldatabase.sqlite"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"finaldatabase.sqlite"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&amp;error];
    if (!success)
    {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}


- (void)initializeDatabase
{

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];
    //NSLog(documentsDirectory);

    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"finaldatabase.sqlite"];
    //NSLog(path);

    if (sqlite3_open([path UTF8String], &amp;database) == SQLITE_OK)
    {
        //NSLog(@"Ok");
    } 
    else
    {
        sqlite3_close(database);
        NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
    }
}



-(void)insert:(NSString *)docname:(NSString *)contact:(NSString *)email;

{

sqlite3_stmt *addStmt = nil;


if(addStmt == nil) 
{
    const char *sql = "insert into Doctorcontacts(doctorname,phoneno,emailid) values (?,?,?)";
    //NSLog(@"sq; %@", sql);
    if(sqlite3_prepare_v2(database, sql , -1, &amp;addStmt, NULL) != SQLITE_OK)
    {
        NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
    }

    //  if(textsession1)
    //  sqlite3_bind_int(addStmt , 1 , textsession1);
    sqlite3_bind_text(addStmt, 1, [docname UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(addStmt, 2, [contact UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(addStmt, 3, [email UTF8String], -1, SQLITE_TRANSIENT);
    if(SQLITE_DONE != sqlite3_step(addStmt))
    {
        NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
    }
    //        else 
    //      {
    //             
    //        }


}

if(addStmt)
{
    sqlite3_finalize(addStmt);
}
sqlite3_close(database);
}

-(IBAction)Savecontacts:(id)sender
{
    NSString *doctor = doctorname.text;
    NSString *phn = doctorcontactno.text;
    NSString *email = doctoremailid.text;
    //  NSLog(@"Username is :%@",usen);
    //  NSLog(@"Password is :%@",passn);
    [self insert:(NSString *)doctor:(NSString *)phn:(NSString *)email];


    UIAlertView  *favAlert=[[UIAlertView alloc] initWithTitle:@"" message:@"Added" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];        
    [favAlert show];
    [favAlert release]; 

    doctorname.text = @"";
    doctorcontactno.text = @"";
    doctoremailid.text = @"";

    // Second *second = [[Second alloc]initWithNibName:@"Second" bundle:[NSBundle mainBundle]];
    //self.navigationController pushViewController:second animated:YES];
    }
</code></pre>
