Professional Documents
Culture Documents
15 Aplicaciones JDBC
15 Aplicaciones JDBC
V8.0
Octubre 2015
Ferreiras
No os
preocupéis, el
señor guiará
sus ovejas
Ferreiras Aplicaciones JAVA, DB, JDBC 3
De un vistazo
Conceptos Básicos
de Bases de Datos
• The word data covers the collection of facts stored in the database;
• Determining what data to enter into the database and how to organize those data is a vital part
of the database designer´s job.
• The word raw indicates that the facts have not ye been processed to reveal their meaning.
• In the raw format are not particularly useful, so they must be transformed into a data summary to
be useful.
5
Data
• Data concept.
• The word raw indicates that the facts have not ye been processed to reveal their meaning.
• In the raw format are not particularly useful, so they must be transformed into a data summary to
be useful.
• Data management
• Focus on the proper generation, storage, and retrieval of data; Given the crucial role that data
play, it should not surprise that data management is a core activity for any business, government
agency, service organization, or charity.
• Timely and useful information requires accurate data. Such data must be properly generated and
stored in a format that is easy to access and process. And, like any basic resource, the data
environment must be managed carefully. 6
Information
• Data computationally processed, stored or transmitted.
Determining what data to enter into the database and how to organize those
data is a vital part of the database designer´s job.
7
Data organization
• It is the arrangement of raw data for its processing in order to converting
them into useful information.
8
Structured and Unstructured
data
• Structured Data are data organized in data structures which describe relationships
among data and operations over them;
• Unstructured data is data that is not organized and, therefore, has no predefined
data model or format specified; They are raw data without format.
• Example of unstructured data is data that can be found in text documents (such
as names, dates ...).
9
Data integrity
The Data Integrity refers to the validity of data; Are data valid? Are data representing for
what they have been designed?
• Each of these categories of the data integrity can be enforced by using the
appropriate constraints ( see later Database Constraints ).
10
Datos
Los datos consisten de hechos en bruto,
tales como:
10008889112 Rafael 20
NombreDeLaTabla
filas
(tuplas)
columnas
INTERNOS
codigo nombre apellido pena
100000045 TOYOTA PEREZ 20
100045678 PERCIO CIVIC 13
100005678 LUIS CANOSO 30
100001333 MARIA CUQUITA 22
See http://en.wikipedia.org/wiki/First_normal_form
Ferreiras Aplicaciones JAVA, DB, JDBC 15
Base de Datos: En un sentido amplio,
una base de datos es cualquier cosa que
almacena datos relacionados. Por
ejemplo, la obsoleta (?) guía telefónica de
papel que almacena nombres y números
telefónicos:
Importante: Cuando
usted vea este icono, le
están indicando que ahí
hay una guía telefónica,
de uso publico, no para
que usted le arranque
las paginas o se la
lleve. .
archivo de personal
Base de Datos
archivo de Ventas
Campos
Accesando a bases de
datos
Base
aplicación controlador SGBD de
Datos
Conecta la
aplicación con la
base de datos a
través del SGBD
Nativo
Es un controlador especifico, escrito para conectar con una
aplicación en especifico. Por ejemplo, un controlador nativo para
conectar Crystar Report ( un generador de reportes ) a una base de
datos.
ODBC
ODBC Son las siglas de Open DataBase Connectivity, y significa
que cualquier base de datos que cumpla con esta norma se puede
comunicar con otras aplicaciones que se ajusten al estándar ODBC.
JDBC
JDBC son las siglas de Java DataBase Connectivity. Es un API de
Java compuesta por un conjunto de clases que se puede utilizar para
desarrollar aplicaciones Java que necesitan acceder a una base
relacional de datos.
...
JDBC
[ Java DataBase Connectivity ]
Ver en http://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html
The following simple code fragment gives a simple example of these three steps:
From http://download.oracle.com/javase/tutorial/jdbc/overview/index.html
Fuente http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html
Ver en http://en.wikipedia.org/wiki/SQL
Ferreiras Aplicaciones JAVA, DB, JDBC 43
SQL
SQL ( del ingles Structured Query
Language), en español “Lenguaje
Estructurado de Consulta”, Es un lenguaje
de programación diseñado para la gestión
de datos en la base de datos relacionales.
Su alcance de aplicación incluye creación y
la modificación esquemas, insertar datos,
consultar, actualizar y eliminar, y el control de
acceso de datos.
Numbers
The precision is a positive integer that determines the number of significant digits
in a particular radix (binary or decimal). The scale is a non-negative integer. A
scale of 0 indicates that the number is an integer. For a scale of S, the exact
numeric value is the integer value of the significant digits multiplied by 10-S.
SQL provides a function to round numerics or dates, called TRUNC (in Informix,
DB2, PostgreSQL, Oracle and MySQL) or ROUND (in Informix, Sybase, Oracle,
PostgreSQL and Microsoft SQL Server).
Ferreiras Aplicaciones JAVA, DB, JDBC 46
Date and time
SQL provides several functions for generating a date / time variable out of a
date / time string (TO_DATE, TO_TIME, TO_TIMESTAMP), as well as for
extracting the respective members (seconds, for instance) of such variables.
The current system date / time of the database server can be called by
using functions like NOW.
Can reference tables not being joined and does not have to reference
either of the tables being joined (though typically it does).
Examples
Syntax: COUNT(*)
Example
SELECT COUNT(*)
FROM Flights
SELECT *
FROM Book
WHERE price > 100.00
ORDER BY title;
Ferreiras Aplicaciones JAVA, DB, JDBC 55
The example below demonstrates a query of multiple
tables, grouping, and aggregation, by returning a list of
books and the number of authors associated with each
book.
SELECT Book.title,
COUNT(*) AS Authors
FROM Book JOIN Book_author
ON Book.isbn = Book_author.isbn
GROUP BY Book.title;
Title Authors
------------------------------------ -----------
SQL Examples and Guide 4
The Joy of SQL 1
An Introduction to SQL 2
Pitfalls of SQL 1
SELECT title,
COUNT(*) AS Authors
FROM Book NATURAL JOIN Book_author
GROUP BY title;
SELECT isbn,
title,
price,
price * 0.06 AS sales_tax
FROM Book
WHERE price > 100.00
ORDER BY title;
line comment. This is indicated by two negative signs (eg. --). The remainder of the text on the line is the comment.
block comment. The start of the block comment is indicated by /*, the end of the comment by */. A block comment can cover text in part of a line, or
can span multiple lines.
rem or @. For Oracle, a line starting with either REM or @ is a comment line.
For many databases, comments are not valid statements. It is expected that the script-processor (in this case AQT) will remove the comments
from the SQL before passing it to the database for processing. Consequently, when running some SQL, AQT will:
remove all line comments from your SQL, except when the Remove Comments option is de-selected (this is discussed later).
not remove any block comments. You should only use block comments with databases that allow these are part of the SQL syntax.
for Oracle, remove all lines starting with rem or @
Remove Comments option
In some circumstances you may want the line comments to remain in your SQL. For instance, you are defining a Stored Procedure and want the
comments to remain as part of the procedure definition.
In this case, go to Options > Run SQL and de-select Remove Comments from SQL. When this option is de-selected, AQT will retain all the line
comments that appear within the body of your SQL statement. Any line comments appearing before the start of your SQL statement will be
removed unless Retain comments before start of SQL is selected.
This option only affects the processing of line comments. Other comments are handled as described earlier.
Beware - if you de-selected this option and include line-comments within normal SQL (such as queries, updates, inserts etc), you may get a syntax
error with some databases.
• Identificador único.
Solo se muestra Vehiculo
las variables que • También se puede
- chasisNo: String <<ID>> usar {isID} o,
encapsulan los
- marca: String simplemente, {id}
atributos.
- precio: double • Democráticamente,
useremos <<ID>>
Aplicaciones Java
con base de datos
aplicación con
Controlador ( ODBC,
base de datos son: JDBC, ... )
Servidor de Base de
Datos ( SGBS )
EVIDENTEMENTE,
Aquí hay cosas que Base de Datos
“conectar” unas con
otras
Ferreiras Aplicaciones JAVA, DB, JDBC 73
Como se organizan estas partes ?
Es establecido por la arquitectura de la
aplicación. La mas común es la llamada
arquitectura de Cliente/Servidor.
Servidor
Contiene el Cliente Contiene la
SGBD y la aplicación
base de datos con la capa
física ( las de
tablas ) presentación
y la capa de
negocio.
Conecta vía
el JDBC con
el SGBD
Las relaciones entre las clases son representadas en una base de datos
relacional usando integridad referencial (FK)
Aplicación OO BD Relacional
Clase Tabla
Atributos Campos o Columnas
Estado de un objeto Fila o tuplas
Identificador único Clave primaria (PK)
Puntero o referencia a otro Clave foránea (FK)
objeto
http://download.oracle.com/javase/7/docs/api/
...