52
Red Hat Database The Web Application Developer’s View Webcast October 30, 2001 Patrick Macdonald, Fernando Nasser Liam Stewart, Neil Padgett Red Hat Database Engineering

The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Red

Hat

Dat

abas

eTh

e W

eb A

pplic

atio

n D

evel

oper

’s

View

Web

cast

Oct

ober

30,

200

1

Patr

ick

Mac

dona

ld, F

erna

ndo

Nas

ser

Liam

Ste

war

t, N

eil P

adge

ttR

ed H

at D

atab

ase

Engi

neer

ing

Page 2: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Age

nda

Red

Hat

Dat

abas

e W

eb In

tera

ctio

n –

Patri

ck M

acdo

nald

Prog

ram

min

g In

terfa

ces

Ove

rvie

w –

Fern

ando

Nas

ser

Dem

onst

ratio

n / E

xam

ples

•O

verv

iew

–Li

am S

tew

art

•Int

erac

tion

with

PH

P –

Nei

l Pad

gett

•Int

erac

tion

with

Jav

a –

Liam

Ste

war

t

Futu

re E

nhan

cem

ents

: GU

I Too

ls –

Nei

l Pad

gett

Q&A

Page 3: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Red

Hat

Dat

abas

e W

eb In

tera

ctio

n

Page 4: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Dat

abas

e as

a W

eb S

erve

r Bac

kend

Sim

plifi

ed V

iew

Brow

ser

Web

Ser

ver

Dat

abas

e

Clie

ntSe

rver

http

Clie

ntSe

rver

Insi

de th

e Se

rver

is

anot

her C

lient

/ Se

rver

hie

rarc

hy

Page 5: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Red

Hat

Dat

abas

e as

a W

eb

Serv

er B

acke

nd

Post

greS

QL

–O

RD

BMS

SQL9

2

Tran

sact

iona

l

ACID

com

plia

nt

Page 6: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Red

Hat

Dat

abas

e as

a W

eb

Serv

er B

acke

ndM

ultip

le s

uppo

rted

prog

ram

min

g la

ngua

ges

and

inte

rface

s fo

r clie

nts

Dat

a in

dexi

ng fo

r ret

rieva

l

Onl

ine

back

ups

Mul

ti-Ve

rsio

n C

oncu

rrenc

y C

ontro

l (M

VCC

)

Page 7: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

UR

Ls o

f Int

eres

tR

ed H

at D

atab

ase

-w

ww

.redh

at.c

om/s

oftw

are/

data

base

Post

greS

QL

-ww

w.p

ostg

resq

l.org

Apac

he -

ww

w.a

pach

e.or

g

Tom

cat -

jaka

rta.a

pach

e.or

g

PHP

-ww

w.p

hp.n

et

Java

/JD

BC -

•ja

va.s

un.c

om/p

rodu

cts

•jd

bc.p

ostg

resq

l.org

Page 8: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Prog

ram

min

g In

terf

aces

Ove

rvie

w

Page 9: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Dat

abas

e C

lient

-Ser

ver A

rchi

tect

ure

Clie

ntAp

plic

atio

nD

atab

ase

Back

end

Clie

ntSe

rver

Cod

e w

ritte

n in

su

ppor

ted

fron

tend

prog

ram

min

g in

terf

ace

Cod

e w

ritte

n in

sup

port

ed

back

end

prog

ram

min

g

inte

rfac

e

Page 10: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Dat

abas

e C

lient

-Ser

ver A

rchi

tect

ure

Clie

ntAp

plic

atio

nD

atab

ase

Back

end

Clie

ntSe

rver

C/C

++, E

mbe

dded

SQ

L in

C, T

cl, P

ytho

n, P

erl,

Emac

sLI

SP

Perl

DB

I, O

DB

C, J

DB

CSQ

L, P

L/pg

SQL,

PL/

Tcl,

PL/P

erl,

C

Page 11: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Dat

abas

e as

a W

eb S

erve

r Bac

kend

Brow

ser

Web

Ser

ver

Dat

abas

e

Clie

ntSe

rver

HTM

L

http

Clie

ntSe

rver

Scrip

ting

Lang

uage

s

Perl,

PH

P, J

SP

Page 12: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Prog

ram

min

g In

terf

aces

Sum

mar

yFr

onte

nd L

angu

ages

•C

/C++

•Em

bedd

ed S

QL

in C

•Tc

l

•Py

thon

(inc

l. D

B-A

PI)

•Pe

rl (in

cl. P

erl D

BI)

•Em

acs

LISP

•JD

BC

•O

DB

C (C

/C++

, Per

l, Tc

l…)

Web

Scr

iptin

g •

PHP

•Pe

rl

•JS

P

Apa

che

mod

or

CG

I int

erpr

eter

(with

Tom

cat o

rsi

mila

r W.A

.S.)

Page 13: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Prog

ram

min

g In

terf

aces

Sum

mar

y

Bac

kend

Lan

guag

es

ts

CPL/P

erl

tPL

/Tcl

tPL

/pgS

QL

sSQ

L

TR

IGG

ER

SE

TO

FLa

ngua

ge

Page 14: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Coh

abita

tion

with

Oth

er D

BM

S

Perl,

C e

tc.

Driv

erM

ngr

OD

BC

Driv

er

OD

BC

Driv

er

PG DB/

2

Ora

cle

OD

BC

API

OD

BC

Driv

er

Page 15: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Coh

abita

tion

with

Oth

er D

BM

S

Perl

Scrip

tD

BI

DBD

:Pg

DBD

:DB2

DBD

:Ora

cle

PG DB/

2

Ora

cle

Page 16: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Dem

onst

ratio

ns /

Exam

ple

O

verv

iew

Page 17: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

PHP

/ Jav

a D

emo

App

licat

ion

Sim

ple

new

s si

te s

imila

r to

Slas

hdot

and

Linu

x To

day

Visi

tors

can

read

arti

cles

pos

ted

by m

oder

ator

s,

post

com

men

ts a

bout

arti

cles

, and

read

co

mm

ents

pos

ted

by o

ther

vis

itors

Des

ign

follo

ws

the

web

clie

nt-s

erve

r mod

el

Impl

emen

ted

in b

oth

PHP

and

Java

with

Red

Hat

D

atab

ase

as th

e da

taba

se b

acke

nd

Page 18: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

PHP

/ Jav

a D

emo

App

licat

ion

Page 19: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

PHP

/ Jav

a D

emo

App

licat

ion

Page 20: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Dat

abas

e Sc

hem

aU

sers

id: i

nteg

er (

prim

ary

key)

hand

le: s

trin

g

emai

l: st

ring

nam

e: s

trin

g

Cat

egor

ies

img_

type

: str

ing

imag

e: b

lob

nam

e: s

trin

g

id: i

nteg

er (

prim

ary

key)

Artic

les

id: i

nteg

er (

prim

ary

key)

head

line:

str

ing

date

: tim

esta

mp

post

er: i

nteg

er

cate

gory

: int

eger

sum

mar

y: s

trin

g

stor

y: s

trin

g

com

men

ts: i

nteg

er

Com

men

tsid

: int

eger

(pr

imar

y ke

y)

artic

le: i

nteg

er

com

men

ts: s

trin

g

post

er: s

trin

g

date

: tim

esta

mp

Page 21: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Dem

onst

ratio

ns /

Exam

ple

Inte

ract

ion

with

PH

P

Page 22: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Usi

ng P

HP

with

Red

Hat

Dat

abas

e

Sim

ilar t

o us

ing

PHP

with

oth

er p

opul

ar

data

base

s

Min

or c

hang

es in

acc

ess

func

tions

PHP

supp

orts

a n

umbe

r of u

sefu

l fea

ture

s w

hen

used

with

Red

Hat

Dat

abas

e (P

ostg

reSQ

L)•

Con

nect

ion

Pool

ing

(Per

sist

ent C

onne

ctio

ns)

•La

rge

Obj

ects

Page 23: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Con

nect

ing

to th

e D

atab

ase

if(!( $connection=pg_pconnect( "host=myhost ".

"dbname=webcastdemo ".

"user=webcastdemo".

"password=mypassword"))) {

echo"<B>Error:</B>";

echo"Could not establish connection to database server.";

echo"<BR>”;

exit;

}

Con

nect

ion

Inde

x

Con

nect

ion

Strin

g

Ope

n a

pers

iste

nt c

onne

ctio

n

Page 24: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Perf

orm

ing

a Q

uery

// Article lookup query

$query="SELECT headline FROM articles";

// Query for all of the articles

if(!( $result= @pg_exec($connection, $query))) {

echo "<B>Error:</B>";

echo "Could not execute article lookup query:";

echo"<PRE>", pg_errormessage($connection), "</PRE>";

exit;

}

Con

nect

ion

Inde

x

Res

ult I

ndex Que

ry S

tring

Page 25: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

A nu

mbe

r of r

elev

ant f

unct

ions

•pg

_res

ult(i

ntre

sult_

id, i

ntro

w_n

umbe

r, m

ixed

fiel

dnam

e)In

dex

into

resu

lt by

row

and

fiel

d

•pg

_fet

ch_r

ow(in

tres

ult,

intr

ow)

Wor

k w

ith a

resu

lt ro

w a

t a ti

me

as a

n en

umer

ated

arra

y

•pg

_fet

ch_a

rray(

intr

esul

t, in

trow

[, in

tres

ult_

type

])In

dex

into

resu

lt as

an

enum

erat

ed a

rray

like

pg_f

etch

_row

()En

hanc

emen

t: In

dex

by fi

eld

num

ber o

r fie

ld n

ame

(ass

ocia

tive

arra

y)

•pg

_fet

ch_o

bjec

t(int

resu

lt, in

trow

[, in

tres

ult_

type

])C

reat

es a

n ob

ject

with

pro

perti

es n

amed

as

the

field

sLi

ke w

orki

ng w

ith a

pop

ulat

ed C

stru

ct

Wor

king

With

Res

ults

Page 26: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Wor

king

With

Res

ults

: An

Exam

ple

<? // Output a list of all of the article headlines?>

<UL>

<?

for( $row=0; $data= @pg_fetch_object( $result, $row); $row++) {

?>

<LI><?=$data->headline?> </LI>

<?

}

?>

</UL>

Itera

te o

ver a

ll re

sults

Echo

the

head

line

Get

the

curre

nt ro

w a

s an

obj

ect

Page 27: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Wor

king

With

Tra

nsac

tions

Man

aged

by

send

ing

SQL

to th

e ba

cken

d

Rel

evan

t SQ

L st

atem

ents

:•

BEG

IN Star

t a tr

ansa

ctio

n

•C

OM

MIT

Com

mit

the

curre

nt tr

ansa

ctio

n to

the

data

base

•R

OLL

BAC

KBa

ck o

ut o

f the

cur

rent

tran

sact

ion

Page 28: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Wor

king

With

Tra

nsac

tions

:A

n Ex

ampl

e (S

lide

1/2)

<?

@pg_exec($connection, "BEGIN");

$query

="INSERT INTO

comments(article,poster,subject,comment)" .

"VALUES (".

$article.

", ".

"'"

.$poster.

"', ".

"'"

.$subject."', ".

"'"

.$comments."')";

if(!@pg_exec( $connection, $query)) {

@pg_exec($connection, "ROLLBACK");

echo "<br> <i>Unable to process request.</i>";

exit;

}

In c

ase

of fa

ilure

,ab

ort a

nd ro

llbac

k

Firs

t, po

st th

e co

mm

ent

Begi

n ou

r tra

nsac

tion

Page 29: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Wor

king

With

Tra

nsac

tions

:A

n Ex

ampl

e (S

lide

2/2)

$query="UPDATE articles SET comments = comments + 1 WHERE id = ".

$article;

if(!@pg_exec($connection, $query)) {

@pg_exec($connection, "ROLLBACK");

echo "<br> <i>Unable to process request.</i>";

exit;

} @pg_exec( $connection, "COMMIT");

?>

<p><i>Your comment has been submitted.</i></p>

In c

ase

of fa

ilure

,ab

ort a

nd ro

llbac

k (re

peat

ed c

ode

–co

uld

use

a fu

nctio

n)

Now

, upd

ate

the

com

men

t cou

nt

Com

mit

the

tran

sact

ion

Rep

ort s

ucce

ss to

the

user

Page 30: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Usi

ng L

arge

Obj

ects

:Im

age

Dat

abas

e Ex

ampl

e

$query

="SELECT image FROM images WHERE id=".

$id;

$result=@pg_exec($connection, $query);

header("Content-type: image/gif");

@pg_exec($connection, "BEGIN");

$image

=pg_loopen($connection, pg_result($result, 0, "image"),

"r");

pg_loreadall($image);

@pg_exec($connection, "COMMIT");

Look

up th

e O

IDof

the

larg

e ob

ject

File

des

crip

tor

Send

the

larg

e ob

ject

to th

e br

owse

r

Send

the

cont

ent t

ype

to th

e br

owse

r

Ope

n th

e la

rge

obje

ct u

sing

the

OID

Page 31: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Dem

onst

ratio

ns /

Exam

ple

Inte

ract

ion

with

Jav

a

Page 32: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Java

and

JD

BC

Java

is a

n ob

ject

-orie

nted

lang

uage

dev

elop

ed b

y Su

n M

icro

syst

ems

JDBC

: Jav

a's

data

base

acc

ess

API

Prov

ides

Jav

a pr

ogra

mm

ers

with

a la

rge

set o

f cla

sses

for

wor

king

with

dat

abas

es

Cod

e w

ritte

n us

ing

JDBC

can

be

used

aga

inst

mul

tiple

da

taba

ses

with

littl

e or

no

chan

ge

Red

Hat

Dat

abas

e pr

ovid

es d

river

s fo

r bot

h JD

BC 1

and

JD

BC 2

Upd

ated

driv

ers

avai

labl

e fro

mPo

stgr

eSQ

L’s

JDBC

web

pa

ge

Page 33: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Impl

emen

tatio

n O

verv

iew

Java

Ser

vlet

s an

d Ja

va S

erve

r Pag

es (J

SP)

used

:•

JSP

for m

ain

inde

x, s

tory

pag

e, a

nd c

omm

ent

subm

issi

on p

age

•Se

rvle

ttha

t ret

rieve

s an

imag

e fro

m th

e ca

tego

ries

tabl

e•

Seve

ral s

uppo

rt cl

asse

s

All u

se J

DBC

for d

atab

ase

acce

ss

Page 34: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Com

mun

icat

ion

Path

way

Clie

ntw

eb-b

row

ser

Apa

che

web

-ser

ver

Tom

cat

appl

icat

ion

serv

er

Red

Hat

Dat

abas

ese

rver

Java

Ser

vlet

san

dSe

rver

Pag

es

Page 35: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Con

nect

ing

to th

e D

atab

ase

A C

onne

ctio

nob

ject

repr

esen

ts a

con

nect

ion

to a

da

taba

seR

eque

st c

onne

ctio

n af

ter l

oadi

ng a

ppro

pria

te

driv

er

<%Class.forName(“org.postgresql.Driver”);

Connectioncon= DriverManager.getConnection(

“jdbc:postgresql://demobox/webcastdemo”,

“webcastdemo”,

“mypassword”);

%>

Dyn

amic

ally

load

and

re

gist

er th

e dr

iver

Req

uest

con

nect

ion

from

dr

iver

man

ager

Page 36: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Perf

orm

ing

a Q

uery

Cre

ate

a St

atem

ento

r a P

repa

redS

tate

men

tob

ject

and

use

its

exec

uteQ

uery

met

hod

to

exec

ute

a qu

ery

Res

ults

sto

red

in a

Res

ultS

etob

ject

and

dat

a ca

n be

acc

esse

d vi

a ac

cess

orm

etho

ds

<%Statementstmt= con.createStatement();

ResultSetrs= stmt.executeQuery(“SELECT headline FROM articles”);

while(rs.next()) {

%>

<LI> <%=rs.getString(“headline”); %> </LI>

<%}

%>

Loop

thro

ugh

resu

lts

Ret

rieve

hea

dlin

efie

ld

Send

que

ry to

dat

abas

e

Page 37: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Perf

orm

ing

an U

pdat

e

Sim

ilar t

o pe

rform

ing

a qu

ery

exce

pt u

se

exec

uteU

pdat

em

etho

d of

Sta

tem

ento

r Pr

epar

edSt

atem

ento

bjec

t

Also

use

d fo

r SQ

L st

atem

ents

suc

h as

C

REA

TE, D

RO

P, e

tc.

If ap

plic

able

, ret

urns

num

ber o

f row

s ch

ange

d (z

ero

othe

rwis

e)

Page 38: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Wor

king

With

Tra

nsac

tions

By d

efau

lt ev

ery

SQL

stat

emen

t is

a co

mpl

ete

trans

actio

n

Use

the

setA

utoC

omm

it, c

omm

it, ro

llbac

km

etho

ds o

f Con

nect

ion

obje

cts

whe

n w

orki

ng

with

mul

ti-st

atem

ent t

rans

actio

ns:

•se

tting

aut

o-co

mm

it m

ode

to fa

lse

ente

rsm

ulti-

stat

emen

t tra

nsac

tion

mod

e•

first

SQ

L st

atem

ent a

fter t

urni

ng o

ff au

to-c

omm

it or

af

ter a

com

mit/

rollb

ack

is s

tart

of tr

ansa

ctio

n•

com

mit

com

mits

all

chan

ges

sinc

e st

art o

f tra

nsac

tion

•ro

llbac

kun

does

all

chan

ges

sinc

e st

art o

f tra

nsac

tion

Page 39: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Wor

king

With

Tra

nsac

tions

:A

n Ex

ampl

e<%Statementstmt= con.createStatement();

con.setAutoCommit(false);

try{

stmt.executeUpdate(“INSERT INTO comments ”+

“VALUES(10, 1, ‘foo’, ‘bar’, now()”);

stmt.executeUpdate(“UPDATE articles SET ”+

“comments = comments + 1 WHERE article=1”);

con.commit();

%><P><I>Your comment has been submitted.</I></P>

<%} catch(Exceptionex) {

con.rollback();

%><P><I>Unable to process request.</I></P>

<%}

%>

Turn

off

auto

-com

mit

Com

mit

all c

hang

es

Any

erro

rs w

ill be

cau

ght a

ndtra

nsac

tion

will

be ro

lled

back

Page 40: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Usi

ng L

arge

Obj

ects

JDBC

sup

ports

inpu

t and

out

put o

f lar

ge o

bjec

ts

Can

use

sta

ndar

d Ja

va I/

O fu

nctio

nalit

y (s

tream

s) w

hen

inse

rting

and

pul

ling

out l

arge

ob

ject

s

Encl

ose

all l

arge

obj

ect o

pera

tions

in a

tra

nsac

tion

Page 41: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Usi

ng L

arge

Obj

ects

:A

n Ex

ampl

e

Statementstmt= con.createStatement();

con.setAutoCommit(false);

ResultSetrs= stmt.executeQuery(“SELECT img_type, image ”+

“FROM categories WHERE id = 3”);

if(rs.next()) {

resp.setContentType(rs.getString(“img_type”));

InputStreamin= rs.getBinaryStream(“image”);

ServletOutputStreamout= resp.getOutputStream();

intb;

while((b = in.read()) != -1) {

out.write(b);

} in.close();

out.close();

} con.commit();

con.setAutoCommit(true);

Ret

rieve

larg

e ob

ject

and

send

to

clie

nt

Page 42: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Dis

conn

ectin

g fr

om th

e D

atab

ase

Cal

l the

clo

sem

etho

d of

Con

nect

ion

obje

ct:

<%

con.close();

%>

Page 43: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Red

Hat

Dat

abas

e Fu

ture

En

hanc

emen

ts P

revi

ew

GU

I Too

ls

Page 44: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Red

Hat

Dat

abas

e G

UI t

ools

Suite

of G

UI t

ools

for d

atab

ase

man

agem

ent,

acce

ss, a

dmin

istra

tion,

and

con

figur

atio

n

Des

igne

d to

allo

w c

ross

-pla

tform

use

•In

itial

rele

ase

of to

ols

for R

ed H

at L

inux

•Su

ppor

t for

oth

er p

opul

ar O

S’s

plan

ned

Prov

ide

enha

nced

eas

e-of

-use

, and

allo

w fa

ster

ad

min

istra

tion

Page 45: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Red

Hat

Dat

abas

e G

UI t

ools

Toda

y’s

Prev

iew

:R

ed H

at D

atab

ase

Adm

inis

trato

r•

GU

I Adm

inis

tratio

n To

ol

•M

anag

e da

taba

se o

bjec

tsU

sers

, Gro

ups,

Inde

xes,

Tab

les,

etc

.

•G

oal i

s to

acc

eler

ate

typi

cal a

dmin

istra

tive

task

sAd

d / D

rop

/ Cre

ate

obje

cts

Gra

nt /

Rev

oke

user

per

mis

sion

set

c.

(con

tinue

d)

Page 46: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database
Page 47: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database
Page 48: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database
Page 49: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database
Page 50: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database
Page 51: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Than

k yo

u!Vi

sit t

he R

ed H

at w

ebsi

te to

lear

n m

ore

abou

t Red

H

at D

atab

ase:

w

ww

.redh

at.c

om/s

oftw

are/

data

base

Com

ing

early

Nov

embe

r, R

ed H

at D

atab

ase

Com

mun

ity P

roje

ct P

ages

: so

urce

s.re

dhat

.com

/rhdb

Upc

omin

g Tr

aini

ng: D

ec 4

-7, D

urha

m, N

.C.

•R

DB

147

–R

ed H

at D

atab

ase

Esse

ntia

ls

Con

tact

Red

Hat

Sal

es

•86

6-2R

EDH

AT

-Opt

ion

2444

•sa

les@

redh

at.c

om

Page 52: The Web Application Developer’s Vie · 2001. 12. 6. · C/C++, Embedded SQL in C, Tcl, Python, Perl, Emacs LISP Perl DBI, ODBC, JDBC SQL, PL/pgSQL, PL/Tcl, PL/Perl, C. Database

Que

stio

ns a

nd A

nsw

ers

All p

artic

ipan

ts a

re o

n m

ute.

Pl

ease

sub

mit

your

que

stio

ns v

ia th

e ch

at fe

atur

e