Databaser, og hvad dertil horer…

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

15 Αυγ 2012 (πριν από 5 χρόνια και 2 μήνες)

332 εμφανίσεις

Introduction to Derby

RHS


2009

2

What is Derby…?


Derby is a DBMS


Database


GUI for administration


GUI for data maintenance


Best part; integrated into NetBeans!


No new installations


If you have NetBeans, you have Derby!

RHS


2009

3

What is Derby…?

We usually work
with Java projects
here…

Now try the
Services tab
instead…

RHS


2009

4

What is Derby…?

Double
-
click
to expand
”Databases”

RHS


2009

5

What is Derby…?


This is the GUI for
creating

and
deleting

databases in Derby


From here, we can
create a
new

database,
which will be located on
our own computer

RHS


2009

6

Creating a database

Right
-
click on ”Java
DB”, and choose
”Create Database”

RHS


2009

7

Creating a database

RHS


2009

8

Creating a database

Give the
database a
proper name

RHS


2009

9

Creating a database

Leave ”User
Name” and
”Password”
empty

RHS


2009

10

Creating a database

As default,
database is
located here…

…but you can
change the loca
-
tion yourself

RHS


2009

11

Creating a database

The (empty)
database
”Friends” has
been created

RHS


2009

12

Creating a database


This is all it takes to create a database in
Derby!


The database is located in the folder you
have specified


You can take a copy of the database,
simply by taking a copy of the folder


At first, the database is empty (of course)

RHS


2009

13

Creating a database


Can anything go wrong…?


Bad name (special characters are probably
not allowed)


Delays (a pop
-
up saying
”…has not started in
5 seconds, do you want to wait longer?”
) Just
choose ”Yes”


Ask for help in case of problems!

RHS


2009

14

Creating a database

Exercise:

1.
Create a database called ”PhoneBook”, using the Derby
DBMS in NetBeans

2.
After having created the database, see if you can find the
folder which contains the database files

3.
Now create a database called ”AddressBook”, but choose a
different location for the database files than the default

4.
Check that the files created for ”AddressBook” are located
where you would expect them to be



RHS


2009

15

Backing up a database


At some point, you may wish to take a
copy of your database, either for backup
or for moving it to another computer


Taking a backup is done simply by
copying the folder in which the database is
stored

RHS


2009

16

Backing up a database

Remember, that we
specified the location
when we created the
database

RHS


2009

17

Backing up a database


What if I have forgotten the location of the
database…?


Databases are stored as subfolders to a
general folder for databases


This general folder can be found by right
-
clicking on the ”Java DB” icon, and choose
”Properties”

RHS


2009

18

Backing up a database

This is the general
folder for storing
databases

RHS


2009

19

Backing up a database


If you have a database called ”CarCata
-
log”, it will be located in a subfolder called
”CarCatalog”, in the folder specified in the
previous dialog


Take a copy of the ”CarCatalog” folder in
order to back up your ”CarCatalog” data
-
base

RHS


2009

20

Restoring a database


Suppose now that I have a copy of a
Derby database, and want to use that
database on another computer


We must perform these three steps:


Determine the folder used for databases on
the computer


Copy the folder containing the database copy
into that folder


Connect to the database

RHS


2009

21

Restoring a database


Determine the folder used for databases
on the computer:


This is done in same way as before, by right
-
clicking on the ”Java DB” icon, and choosing
”Properties”


Of course, this assumes that NetBeans and
Java DB has been properly installed on the
computer…

RHS


2009

22

Restoring a database

This is the general
folder for storing
databases

RHS


2009

23

Restoring a database


Copy the folder containing the database
copy into that folder:


This is just a matter of simple file copying,
from e.g a USB key into the general folder for
storing databases


RHS


2009

24

Restoring a database


Connect to the database:


Just copying the database folder is
not

enough to make it show up in the list of
databases; we must connect to it


Under the ”Databases” icon, expand the
”Drivers” tab


Right
-
click on the ”Java DB (Network)” icon,
and choose ”Connect using…”


A connect dialog will appear…

RHS


2009

25

Restoring a database

RHS


2009

26

Restoring a database


In the connection dialog, we must supply
the information needed to make a
connection to the copied database


Host: localhost

(since the database in on the
computer itself)


Port: 1527

(standard port used by Derby)


Database
: The exact name of the database


User name & password
: We usually leave
these blank

RHS


2009

27

Restoring a database

RHS


2009

28

Restoring a database


If everything is in order, you will be taken
to the ”advanced” tab of the dialog when
you press ”OK”


Here you just verify that the ”APP” schema
should be used


in other words, just
press ”OK” again


RHS


2009

29

Restoring a database

Just press
OK here…

RHS


2009

30

Restoring a database

The new
connection
has been
established