Download presentation
Presentation is loading. Please wait.
1
Data
2
Java E-Commerce © Martin Cooke, 2003
Plan Issues in data-handling Relational database and SQL refresher XML vs relational databases Next lecture: Java database connectivity API (JDBC) 14/04/2019 Java E-Commerce © Martin Cooke, 2003
3
Issues in data handling on the web
4
Java E-Commerce © Martin Cooke, 2003
persistent? structure? portable? available? concurrent access? secure? transactionally safe? 14/04/2019 Java E-Commerce © Martin Cooke, 2003
5
Java E-Commerce © Martin Cooke, 2003
persistent? Granting immortality to your data instances Persistence = data living beyond the immediate lifecycle of the processes manipulating it A relational database is the primary tool for persistence, and has been for decades Can be handled automatically using an appropriate ‘container’ (see EJBs) structure? portable? available? concurrent access? secure? transactionally safe? 14/04/2019 Java E-Commerce © Martin Cooke, 2003
6
Java E-Commerce © Martin Cooke, 2003
persistent? Free text Most of the web Tabular Vast amounts of existing data (forced into tabular form?) Tree-structured Marked up content eg XML Tedious to handle relationally Arbitrary object Images, sound files Tricky to handle relationally Object-relational or object database structure? portable? available? concurrent access? secure? transactionally safe? 14/04/2019 Java E-Commerce © Martin Cooke, 2003
7
Java E-Commerce © Martin Cooke, 2003
persistent? Free text Most of the web Tabular Vast amounts of existing data (forced into tabular form?) Tree-structured Marked up content eg XML Tedious to handle relationally Arbitrary object Images, sound files Tricky to handle relationally Object-relational or object database structure? portable? available? concurrent access? secure? transactionally safe? Our focus in this lecture is on tabular data 14/04/2019 Java E-Commerce © Martin Cooke, 2003
8
Java E-Commerce © Martin Cooke, 2003
persistent? Vast volumes of data must be … searched rapidly … available 24x7 (eg credit card checking) … accessible by many concurrent users Rely on optimised database engines which have been honed over the years structure? portable? available? concurrent access? secure? transactionally safe? 14/04/2019 Java E-Commerce © Martin Cooke, 2003
9
Java E-Commerce © Martin Cooke, 2003
persistent? Modification Dirty reads and writes Pessimistic vs optimistic concurrency Efficiency How to manage multiple connections? Expensive to create Limited in number for typical databases structure? portable? available? concurrent access? secure? transactionally safe? 14/04/2019 Java E-Commerce © Martin Cooke, 2003
10
Java E-Commerce © Martin Cooke, 2003
persistent? To maintain consistency, it often makes sense to carry out a group of changes (a transaction) to data credit card db and order db If one statement in the transaction fails, data can be left in an inconsistent state must be able to unwind (rollback) the transaction structure? portable? available? concurrent access? secure? transactionally safe? 14/04/2019 Java E-Commerce © Martin Cooke, 2003
11
Java E-Commerce © Martin Cooke, 2003
persistent? Just how secure are files left lying around the place? Again, rely on existing secure solution in relational database Introduces its own layer of authentication structure? portable? available? concurrent access? secure? transactionally safe? 14/04/2019 Java E-Commerce © Martin Cooke, 2003
12
Java E-Commerce © Martin Cooke, 2003
persistent? Java may be portable, but what about its dependence on existing databases? Ideally, no vendor tie-in avoid legacy data problems in future Tricky in practice since industry standard (SQL) is not as standard as it seems structure? portable? available? concurrent access? secure? transactionally safe? 14/04/2019 Java E-Commerce © Martin Cooke, 2003
13
Relational database and SQL refresher
Nobody fails the databases course
14
(Relational) data model
student module lecturer 14/04/2019 Java E-Commerce © Martin Cooke, 2003
15
Java E-Commerce © Martin Cooke, 2003
id name 1 Java 2 Databases … student stud/mod module sid mid 1 2 id name SSID 1 B Black 2 J Brown … lecturer 14/04/2019 Java E-Commerce © Martin Cooke, 2003
16
Java E-Commerce © Martin Cooke, 2003
SQL CREATE command student stud/mod module id name SSID 1 B Black 2 J Brown … lecturer CREATE TABLE student ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(4), SSID INT DEFAULT 0 ) CREATE TABLE student ( id INT, name TEXT, SSID INT ) 14/04/2019 Java E-Commerce © Martin Cooke, 2003
17
Java E-Commerce © Martin Cooke, 2003
SELECT statement id name 1 Java 2 Databases … student stud/mod module sid mid 1 2 id name SSID 1 B Black 2 J Brown … lecturer SELECT module.name FROM module,student,studMod WHERE module.id = mid AND student.name = ‘B Black’ AND student.id = studMod.sid; SELECT name FROM student WHERE id = 2; 14/04/2019 Java E-Commerce © Martin Cooke, 2003
18
Java E-Commerce © Martin Cooke, 2003
CREATE and INSERT CREATE TABLE student ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50) NOT NULL, SSID INT DEFAULT 0 ); INSERT INTO student VALUES(1,'Joe Bloggs', ); INSERT INTO student VALUES(20,'Bob Black',null); INSERT INTO student VALUES(4,'Gill Brown', ); 14/04/2019 Java E-Commerce © Martin Cooke, 2003
19
Java E-Commerce © Martin Cooke, 2003
SELECT SELECT * FROM student; 14/04/2019 Java E-Commerce © Martin Cooke, 2003
20
Java E-Commerce © Martin Cooke, 2003
UPDATE UPDATE student SET name = ‘Gill Bloggs’ WHERE id = 4; 14/04/2019 Java E-Commerce © Martin Cooke, 2003
21
Java E-Commerce © Martin Cooke, 2003
JOIN Find all modules taken by Bob Black 14/04/2019 Java E-Commerce © Martin Cooke, 2003
22
Java E-Commerce © Martin Cooke, 2003
Other SQL DELETE Deletes rows from a table DELETE FROM student WHERE name=‘fred’; 14/04/2019 Java E-Commerce © Martin Cooke, 2003
23
Java E-Commerce © Martin Cooke, 2003
Other SQL DELETE Deletes rows from a table DELETE FROM student WHERE name=‘fred’; DROP Permanently remove database or table from the system DROP DATABASE studs; DROP TABLE student; 14/04/2019 Java E-Commerce © Martin Cooke, 2003
24
Java E-Commerce © Martin Cooke, 2003
Other SQL DELETE Deletes rows from a table DELETE FROM student WHERE name=‘fred’; DROP Permanently remove database or table from the system DROP DATABASE studs; DROP TABLE student; DESCRIBE Give information about a table or column DESCRIBE student; 14/04/2019 Java E-Commerce © Martin Cooke, 2003
25
Java E-Commerce © Martin Cooke, 2003
Other SQL DELETE Deletes rows from a table DELETE FROM student WHERE name=‘fred’; DROP Permanently remove database or table from the system DROP DATABASE studs; DROP TABLE student; DESCRIBE Give information about a table or column DESCRIBE student; SHOW Display information about system SHOW DATABASES SHOW TABLES [FROM db] 14/04/2019 Java E-Commerce © Martin Cooke, 2003
26
Java E-Commerce © Martin Cooke, 2003
Datatypes SQL2 BIT, TINYINT, SMALLINT, INTEGER, BIGINT, REAL, FLOAT, DOUBLE, DECIMAL, NUMERIC, CHAR, VARCHAR, LONGVARCHAR, DATE, TIME, TIMESTAMP, BINARY, VARBINARY, LONGVARBINARY emphasis on Primitive types Storage size SQL3 BLOB, CLOB, ARRAY, REF, STRUCT 14/04/2019 Java E-Commerce © Martin Cooke, 2003
27
Java E-Commerce © Martin Cooke, 2003
More on datatypes Different database engines support their own types internally and loosely translate to an SQL2 type Big mismatch between rich Java type possibilities and SQL datatypes Care needed, though JDBC helps (later) 14/04/2019 Java E-Commerce © Martin Cooke, 2003
28
Choices and integrations
Relational data vs XML Choices and integrations
29
Persistence is not the issue
Need to consider questions of data representation and persistence separately Can store/retrieve XML as a string on a relational database 14/04/2019 Java E-Commerce © Martin Cooke, 2003
30
Java E-Commerce © Martin Cooke, 2003
Which to use? pros cons XML Good for complex data Reasonably good fit to object-based software Storage-hungry Slow to build and search documents Relational data Good for tabular data Optimised for memory and speed, especially for multi-factor searches Tricky for tree-structured data Very tricky for arbitrary objects: needs transformation 14/04/2019 Java E-Commerce © Martin Cooke, 2003
31
Complementary aspects
Store XML together with some search terms Convert SQL to XML Represent SQL query in XML 14/04/2019 Java E-Commerce © Martin Cooke, 2003
32
Resources
33
Java E-Commerce © Martin Cooke, 2003
Book Yarger, Reese and King (1999) MySQL and mSQL, O’Reilly, Check if later version 14/04/2019 Java E-Commerce © Martin Cooke, 2003
34
Java E-Commerce © Martin Cooke, 2003
Online documents An online SQL interpreter 14/04/2019 Java E-Commerce © Martin Cooke, 2003
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.