SQLite C/C++- CREATE and OPEN SQLite Database using C/C++
Make a C Program file and Name it as main.c and write the following C/C++ Code
Basic Syntex
#include <sqlite3.h> #include <stdio.h> int main(int argc, char* argv[]) { sqlite3 *db; int rc; rc = sqlite3_open("student.db", &db); if( rc ){ fprintf(stderr, "Can not open database: %s\n", sqlite3_errmsg(db)); return 0; }else{ fprintf(stderr, "Student database Created and Opened successfully\n"); } sqlite3_close(db); return 0; }
$ gcc main.c -l sqlite3 $ ./a.out Student database Created and Opened successfully
You will also notice a SQLite database named test.db in the same folder containing you main.c file
$ ls a.out main.c student.db
Leave a Reply