i was getting familiar with sqlite and try to insert the values into database but giving exception. tf1 and tf2 are object of textfield. here is my code:
@synthesize tf1, tf2, add, disp; -(id)initApp { if(![super init]) return nil; //DB stored in application bundle NSString *DBName = @"kbase.sqlite"; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingString:DBName]; db = [FMDatabase databaseWithPath:path]; [db setLogsErrors:TRUE]; [db setTraceExecution:TRUE]; if(![db open]) { NSLog(@"Could not open Database"); return 0; } else { NSLog(@"Database opened successfully"); } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self initApp]; [add addTarget:self action:@selector(insertButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; [disp addTarget:self action:@selector(displaytButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; } -(IBAction)insertButtonClicked :(id)sender { NSLog(@"insert"); NSLog(@"db.....%@",db); [db executeUpdate:@"insert into info values (?,?)", tf1.text, tf2.text]; [self resignFirstResponder]; } -(IBAction)displayButtonClicked:(id)sender { NSString *str1 = tf2.text; NSString *returnResult = [[NSString alloc]init]; FMResultSet *rs = [db executeQuery:@"select name from info where rollno = 1"]; while ([rs next]) { returnResult = [rs stringForColumn:@"rollno"]; [tf1 setText:returnResult]; [tf2 setText:returnResult]; } }
databse is opening successfully and controll terminate after printing insert exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL executeQuery:]: unrecognized selector sent to instance 0x3d30ef0'
i am not able to configure the problem. plz help.