WEEK 9 2012 DATABSE USAGE

bawltherapistΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 3 μήνες)

62 εμφανίσεις


WEEK
9

2012

DATABSE USAGE

SQLite DATABASE

SQLite is quite versatile. It is a database, a programming library, and a command
-
line tool, as well an

excellent learning tool that provides a good introduction to relational databases. There are many ways
to use

it

in embedded environments, websites, operating system services, scripts, and applications.
For programmers, SQLite is like “data duct tape,” providing an easy way to bind applications and their
data.

Like duct tape, there is no end to its potential uses
. In a web environment, SQLite can help with

managing complex session information. Rather than serializing session data into one big blob,

individual pieces can be selectively written to and read from individual session databases. SQLite also

serves as a g
ood stand
-
in relational database for development and testing: there are no external
RDBMSs or networking to configure or usernames and passwords to hinder the programmer’s focus.
SQLite can also serve as a cache, hold configuration data, or, by leveraging
its binary compatibility
across platforms, even work as an application file format. The basic SQLite can be obtained from
http://www.sqlite.org/download.html
. In this internet site documentation is given

as

sqlite
-
doc
-
3070800.zip

(3.24 MiB)


This ZIP archive contains most of the static HTML files that comprise this
website, including all of the SQL Syntax and the C/C++ interface specs and other

miscellaneous documentation.

Precompiled binaries for Microsoft computers are given as:

Precompiled Binaries For Windows


sqlite
-
shell
-
win32
-
x86
-
3070800.zip

(248.28 KiB)


A
command
-
line shell

for accessing and modifying SQLite databases. This
program is compatible with all versions of SQLite through 3.7.8 and beyond.



sqlite
-
dll
-
win32
-
x86
-
3070800.zip

(282.40
KiB
)


This ZIP archive contains a DLL for the SQLite library version 3.7.8. The
DLL is built using
SQLITE_ENABLE_COLUMN_METADATA

so that it is
suitable for use with Ruby on Rails.

The site also contains precompiled binaries for different machine operating systems such as Linux,
Mac. Please refer to the site for the details.


When you opened
sqlite
-
shell
-
win32
-
x86
-
3070800.zip

an executable program sqlite3.exe will be
available, by running this program in dos Shell , SQLite database can be directly used.


Java version of the SQLite can be obtained from internet
adress
http://www.zentus.com/sqlitejdbc/

as
pure java file in jar format as
sqlitejdbc
-
v056.jar
.
After receiving the file, copy it to
.
./java/jre/lib/ext/ directory for direct Access to it.


EX1 )

Investigate the following programs


Main program

Program does

Additional
files &
classes

Example java library class
its using

COFFEE
.java

Create an SQLite database table
COFFEE in a database c
alled
COFEE.db and
insert data by using


insert statement
then select the table

COFFEE
1.java

Create an SQLite database table
COFFEE in a database called
COFEE.db and
read coffee data from
sequaentşial file coffee.txt , insert
data then select the table

coffee.txt


select_COFFEE
.java

Select an SQLite database table
COFFEE in a database called
COFEE.db



SQLight_Table
.java

Execute any given SQLite querry for
a given da
tabase file

QueryTableModel
.java


H9Ex1.java


Read x and y data from sequential
file a.txt create database table H9Ex1
insert x and y data into the table
update y2 data as y*y read results
database : H9

a.txt




H9Ex2.java


Read T and CV data from sequen
tial
file
co2_cv.txt
create database table
H9Ex2 insert T and CV data into the
table update TK as data T+273.15
read results. database: H9


Co2_cv.txt




H9Ex3.java

Create x data rom for loop, calculate
sin(x) from java create database table
H9Ex3 insert
x and sinx data into the
table read results. database : H9





H9Ex4.java

Read x data from sequential file b.txt
create database table H9Ex4 calculate
average value from sql function AVG
then read result and print it. database :
H9

b.txt


createadressboo
k.java

Create adressbook, if adressbook is
already existed first drop (delete) the
adressbook and then create it



Adressbook.java

Use database table adressbook, enter
new adresses find any desired adress,
delete adress etc.

adresspanel.java

outputpanel.j
ava

deleteadress.java

findadress.java

inputadress.java

help.java




EX2)
Temperature and specific heat of CO
2

gas is given in file co2_cv.txt . Read the data, from the
file and
calculate average temperature and cv value. Write it to H9Ex2A.java

EX 3
) :
Read x and y values from file d.txt. Write x and
y
values into
database table H9Ex3A, read
results from the table and print it on the screen

EX4
)

EX3) :
Enter the following data into database table data1

1

2

2


4

3

9

4

16


HOMEWORK
S

HW 1 :

Create table
student

with data fields
name

String, surname String
, grade1
double
, grade 2
double
, result
double

Input the following data

‘Ali’ ‘Çiçek’ 24 58

‘Veli’ ‘Durmuş’ 49 73

‘Hasan’ ‘Yücel’ 72 68

‘Mehmet’ ‘Demir’ 63 55

Calculate resul
t as 40% grade1 and 60% grade2 and write down into database result column. Print out
the results.

HW 2 :
Temperature and specific heat data of CO
2

gas is entered to CO2 table in exercize 1 . Read
the data, from database temp.CO2, calculate the avarage
temperatures and avarage CV value and print
out the results.

HW3 :

The following data is given in e.txt file read data
wtite x and exp(y) into database table
H9HW3

X

y

0

-
1.33E
-
04

0.1

0.099957578

0.2

0.19880847

0.3

0.295555559

0.4

0.389335044

0.5

0.479283123

0.6

0.564535991

0.7

0.644229849

0.8

0.717500892

0.9

0.783485319

1

0.841319327