Transcript Document
Introduction to SQL
Using MySQL and JDBC
Mujtaba Talebi
11/11/2005
Applied Computing Technology Laboratory
The SQL Language
Developed in 1970
Created by IBM, Donald D. Chamberlin,
Raymond F. Boyce
Uses Declarative paradigm – describes a
problem rather than defining a solution.
The most popular language used to
create, modify, and retrieve data from
relational databases.
Applied Computing Technology Laboratory
2
SQL Advantages
Simple and easy to use.
There is a diverse array of SQL
implementations.
Considered to be great for handling very
large database needs.
Applied Computing Technology Laboratory
3
SQL Disadvantages
Porting SQL code from one major
database to another is hard.
The SQL standard is large and complex,
so most databases do not implement it
fully.
Some areas of the SQL standards such
as semantics are ambiguous.
It is possible to get stuck with a system.
Applied Computing Technology Laboratory
4
SQL a true programming language?
The debate rages on….
We have to ask ourselves, is the language
Turing complete?
The answer to this question is no.
SQL is not a general programming language.
SQL is designed specifically to be used with
databases.
People still argue about this question.
Applied Computing Technology Laboratory
5
MySQL Documentation
Available here:
http://dev.mysql.com/doc/refman/5.0
/en/index.html
Discusses:
History
How to install and use
Standards compliance (ANSI/ISO)
Much more
Applied Computing Technology Laboratory
6
SQL92 Grammar
Not widely available:
http://www.programmar.com/ex_sql2.htm
Example:
grammar SQL2 <IGNORECASE,
SPACE = space_symbol,
HIDELITERALS,
NOBACKTRACK>
{
start ::=
{direct_sql_stmt [";"] };
direct_sql_stmt ::=
direct_sql_data_stmt
| SQL_schema_stmt
| SQL_transaction_stmt
| SQL_connection_stmt
| SQL_session_stmt
;
Applied Computing Technology Laboratory
7
Step 1: Install MySQL
Download MySQL from:
http://dev.mysql.com/downloads/
Read the installation instructions.
Run the installer and choose default
choices.
Go back and read the installation
instructions if you have trouble.
Applied Computing Technology Laboratory
8
Step 2: Install MySQL Administrator
MySQL Administrator is a graphical utility
that lets you manage your MySQL server
and databases.
Download & install from:
http://www.mysql.com/products/tools/administrator/index.html
Run the installer and choose the default
settings.
Example.
Applied Computing Technology Laboratory
9
Step 3: Install the MySQL JDBC Connector
Download from:
http://dev.mysql.com/downloads/
Unzip to a folder.
Copy the “mysql-connector-java-3.1.11bin.jar” file to your JAVA library directory.
For me it was here:
C:\Program Files\Java\jdk1.5.0_04\lib
Applied Computing Technology Laboratory
10
Step 4: Learn to use the command line.
Run the “MySQL Command Line Client
from the Start Menu, it is under:
Programs->MySQL->MySQL 5.0
Enter the root password.
You can now insert SQL statements and
other commands.
Example.
Applied Computing Technology Laboratory
11
Step 5: Create a JAVA program.
Create a JAVA program.
Import the java.sql package.
Load the JDBC driver.
Establish a connection to the database.
At this point, you can complete regular
SQL queries like I showed you from
before, within JAVA.
Example.
Applied Computing Technology Laboratory
12
Learning more about SQL:
Beginning
MySQL Tutorial
For good descriptions of SQL
commands, please visit here.
SQL92 Grammar
MySQL Implementation
http://www83.homepage.villanova.edu/m
ujtaba.talebi/index.htm
Applied Computing Technology Laboratory
13