You are on page 1of 8

SQLite Tutorial

Created by

Bernhard Preisler <info@bpreisler.com>

Created date

15.02.2013

Version

05.03.2013

Contents
1 What is SQLite?

2 Motivation

3 Performance
3.1 SQLite vs. MySql . . . . .
3.1.1 Insert Statements .
3.1.2 Update Statements
3.1.3 Select Statements .

.
.
.
.

3
3
3
4
4

4 Installing SQLite
4.1 Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 Netbeans . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4
4
6

5 SQLite Pracitcal
5.1 Connect to SQlite
5.2 Create Table . . .
5.3 Insert Statement .
5.4 Update Statement
5.5 Select Statement .
5.6 Delete Statement .

6
7
7
8
8
8
8

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

6 SQLite Class

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

What is SQLite?

SQLite is a opensource, serverless database what makes it easy to use for programs to handle own data easily. It is designed to use minimal requirements
and libraries that SQlight became a great popularity for applications which
may not consume a lot of electricity. Inter alia supports SQLite DBMS,
transactions, subselects and views and most operations of other databases
can be compiled into SQLite, but a few exceptions and constraints will meet
us (GRANT, REVOKE). In SQLite you havent a server architecture to run
in the background which is the most significant difference between other
database systems. SQLite has only a libriary for Tlc, so we have to fall back
to an external library.

Motivation

Our goal in this tutorial is to use SQLite on Eclipse for the programming
language Java. I wont explain Java expressions or sql statements, cause this
will blow up the tutorial in a wring way. If you have questions or additions
that improve the tutorial you can contact me1 .

Performance

I think it is a little bit interesting how sql scale and which one perform
better. I will run the tests on a Windows 7 machine which had a dual core,
4 gigabyte RAM and the Version 3.7.2 of the JDBC SQLite Driver. All
those thinks are local on my machine, because I dont want to risk that the
internet are to slow or affect the results and shut down all programs.
SQLite database: Download

3.1

SQLite vs. MySql

First we examine the performance difference between SQLite and MySql.The


MySql class is from IT Blogging and I modified methods a little bit. I
used the actual MySql JDBC Connector Version 5.1.23 and the MySql 5.6
Version.
MySql database: Download
3.1.1

Insert Statements

Lets try to find out which insertion statement are faster.


1

info@bpreisler.com

Statements SQLite (ms)

MySql (ms)

1.000
10.000
100.000

3104 - 3476 (100%)


37267 - 41298 (100%)
393625 - 522264 (100%)

6374 - 7243 (207%)


68211 - 72550 (179%)
721214 - 816084 (168%)

As we see, SQLite is a little bit slower than MySql on the insert statements.
3.1.2

Update Statements

Following soon.
3.1.3

Select Statements

Following soon.

Installing SQLite

This section will engage with the installing of SQLite.

4.1

Eclipse

Preconditions
Install SQLite with Eclispe. This installiation is a lot of easier than other
SQLs, dont put off.
1. First you have to download and run Eclipse. After youve created a
project you can add the SQL class into your project.
2. Now you clicking on Properties on your project.

3. Click on Java Build Path Libraries Add External JARs Choose


Your Path to the SQLite JAR File Add it

4. Now you see in your project that you add a SQLite referenced Library.
It should look like the following picture.

SQLite is installed into your project, it is quite simple.

4.2

Netbeans

Following soon.

SQLite Pracitcal

Now we switch to the practical part of the documentation. You can read
this part without get the earlier chapter.

5.1

Connect to SQlite

With the following Code in Listing 1 you can establish a connection to the
local SQLite database.
Listing 1: Java: Connect to the database of SQLite
import j a v a . s q l . ;
C l a s s . forName ( o r g . s q l i t e .JDBC ) ; // C l a s s f o r name
c o n n e c t i o n = DriverManager . g e t C o n n e c t i o n ( j d b c : s q l i t e : / +
D: / Dropbox / P r o j e k t e / Java / SQLite +
/db/ +
YourDatabaseName +
. db ) ;
statement = connection . createStatement ( ) ;

5.2

Create Table

To create a table we used the function executeUpdate(String) to execute a


create table statement.
If there are no declared definitions for a column, the column will be created
with the definition NULL. The other definitions are NOT NULL, CHECK,
UNIQUE, PRIMARY KEY. Important to know is that the table name
must not start with sqlite , this generates an error.
Listing 2: Java: Create a table
s t a t e m e n t . executeUpdate (
CREATE TABLE IF NOT EXISTS t e s t (
i d INTEGER PRIMARY KEY,
forename TEXT NOT NULL,
l a s t n a m e TEXT NOT NULL
);
);
We see that the statemant for creating a new table is highly similar to a
normal SQL statement.

Specifcation Type
TEXT
NUMERIC
INTEGER
REAL
NONE

TEXT
NUM
INT
REAL
(emtpy)
7

As you can see there a limited of typs you can use to use in your columns.

5.3

Insert Statement

Following soon.

5.4

Update Statement

Following soon.

5.5

Select Statement

Following soon.

5.6

Delete Statement

Following soon.

SQLite Class

Following soon.

You might also like