Saturday, July 14, 2012

Integration of SQLite3 and Netbeans C/C++ IDE

Few days back, I wanted to use SQLite database for one of my project. I spend couple of hours to find a way to integrate with Netbeans. Maybe many of us will be clever enough to just follow the information given on SQLite website to accomplish this task, but people like me can follow this blog post :)
I am using Netbeans C/C++ IDE ver. 7.1.2 and SQLite ver. 3.7.13 and Windows 7 OS.


Download links for:
I hope, all above files are being downloaded in one folder for future use or give away to others :P

Installation Procedure:
Installation of Cygwin, Netbeans, and SQLite Database browser is straight forward, hopefully for everyone. But in order to install SQLite source code that we downloaded before, need procedure given below.

Compile SQLite using Cygwin:
Open Cygwin Terminal, then;
  1. Locate Z:\Cygwin\home\your_name. 'Z' is the drive name where Cygwin is installed, and 'your_name' is YOUR NAME :P.
  2. Copy source code file 'sqlite-autoconf-3071300.tar.gz' to directory mentioned in point 1.
  3. Start Cygwin.
  4. Enter into Z:\Cygwin\home\your_name. By default, Cygwin terminal is in home\your_name directory. You can check using 'pwd' command, if response is negative then use 'cd' to change directory.
  5. tar -xzvf sqlite-autoconf-3071300.tar.gz (To unzip)
  6. Enter sqlite-autoconf-3071300, e.g. cd sqlite-autoconf-3071300. Then
  7. ./configure
  8. make
  9. make install
Great, we compiled the SQLite, but what we are interested in are two library files which are located in C:\cygwin\usr\local\lib, and SQLite3 Header file located in C:\cygwin\usr\local\include. These header and library files will be used in linking Netbeans project with SQLite database;
  • sqlite3.h
  • libsqlite3.a
  • libsqlite3.dll.a
Include Header and Library files in Netbeans:
  • Include header file; #include <sqlite3.h>
  • Go to project settings of your Netbeans project. Then 'build->linker->libraries', and give reference to above two libraries.
And we are done here, now we can write queries and access database using C/C++ code.