Beruflich Dokumente
Kultur Dokumente
Relational Databases
A database contains
The data Metadata about the schema Metadata about the indexes
The data can be accessed directly using SQL (Structured Query Language) this is the most important programming language in business applications (sorry, Java) You can communicate with a database using TCP/IP network packets.
Parts of a database
Tables: Hold the data Queries: Present data from one or many tables that are joined together Stored Procedures: Compiled SQL statements residing on the database. They may have input and/or output parameters Triggers: An event listener that is triggered when data changes in a given table
SQL Statements
SELECT column1, column2, column3 FROM tableName WHERE column3 = value AND column4=value; UPDATE tableNAME SET column1=value1, column2=value2 where keyColumn=keyValue; DELETE FROM tableName where column1=value; INSERT INTO tableName(col1, col2) VALUES(value1, value2);
Primary key
Used to uniquely identify a record Must exist for every record in every table Can be a business key
A single unique field, or Multiple fields that, when combined, are unique
Foreign Keys
A foreign key is a relationship to another table (object) Can be represented object-wise by an object that HAS-An array of other objects Can be
One to Many Many to Many (requires an intermediary table) One to one (consider if you really need it)
SQL Dialect
Depending on the database product, the SQL used is slightly different It should be mostly the same across all for simple SQL commands; however, each DBMS (database management system) provides its own set of goodies that arent standard across all products
Type II
Uses additional drivers at the network connectivity layer Written in native code Must be installed on every machine Example: IBM DB2 Connect
Type IV
Written in Java and contains networking code in its classes No additional installation on the client or server, connects to services the DB already provides
Plug-and-play
Once you install a driver, the language you write (both Java and SQL) is the same so you can swap out connection types by changing only your connection code If you switch to use a different database (SQL Server to mySQL, for example), your Java code does not change, but your SQL might, depending on how close the dialect is
Classpath
If your type IV driver is in a jar file, dont forget the conventions: To compile javac ConnectToMySQL.java -classpath ".\mysql-connector-java-3.1.12bin.jar To run: D:\docs\ITT\Java II\Week6\examples>java -classpath ".\mysql-connector-java-3.1.12bin.jar;." ConnectToMySQL
Other resources
http://www.developer.com/java/data/article.php/3417381
http://www.kitebird.com/articles/jdbc.html