Upload
ghuru
View
234
Download
0
Embed Size (px)
DESCRIPTION
jdbc
Citation preview
GOALS1. Database Systems2. Introduction3. Structured Query Language4. SQL Data Types5. Creating Table in SQL6. Simple Database Application7. Client – Server Application8. Three Tier Application9. Typical Uses of JDBC
DATABASE SYSTEMS• System containing repository of “DATA” (or)
“INFORMATION” is called as Database Systems.
• Most popular form of database system is the “Relational Database System”.
• Structured Query Language (SQL) is used among relational databases to construct queries.
• Using SQL, Java Applications need to query Back-end Databases.
DATABASE SYSTEMS• Relational database– Table=> A Data Structure comprising of Rows, Columns– Record=> Horizontal Set of Row of data in the Table– Field=> Vertical Set of Column Data in the Table– Primary key=> Unique Column that identifies a Row.• Unique data
• SQL statement– Query=> Similar to English Programming Statement,– => Used to fetch data from table (or) tables.
STRUCTURED QUERYLANGUAGE
• BASIC SQL QUERY :-• Simplest format of a SELECT query– SELECT * FROM tableName– SELECT * FROM authors
• Select specific fields from a table– SELECT authorID, lastName FROM authors
STRUCTURED QUERYLANGUAGE
• BASIC SQL QUERY USING “WHERE” CLAUSE :-• specify the selection criteria– SELECT fieldName1, fieldName2, … FROM tableName WHERE criteria
– SELECT title, editionNumber, copyrightFROM titles
WHERE copyright > 1999
• WHERE clause condition operators– <, >, <=, >=, =, <>– LIKE
• wildcard characters % and _
STRUCTURED QUERYLANGUAGE
• BASIC SQL QUERY USING “WHERE” CLAUSE :-• SELECT authorID, firstName, lastName
FROM authorsWHERE lastName LIKE ‘D%’
STRUCTURED QUERYLANGUAGE
• BASIC SQL QUERY USING “WHERE” CLAUSE :-• SELECT authorID, firstName, lastName
FROM authorsWHERE lastName LIKE ‘_i%’
STRUCTURED QUERYLANGUAGE
• BASIC SQL QUERY- “ORDER BY” CLAUSE :-• Optional ORDER BY clause– SELECT fieldName1, fieldName2, … FROM tableName ORDER BY field ASC
– SELECT fieldName1, fieldName2, … FROM tableName ORDER BY field DESC
• ORDER BY multiple fields– ORDER BY field1 sortingOrder, field2 sortingOrder, …
• Combine the WHERE and ORDER BY clauses
STRUCTURED QUERYLANGUAGE
• BASIC SQL QUERY- “ORDER BY” CLAUSE :-• SELECT authorID, firstName, lastName
FROM authorsORDER BY lastName ASC
STRUCTURED QUERYLANGUAGE
• BASIC SQL QUERY- “ORDER BY” CLAUSE :-• SELECT authorID, firstName, lastName
FROM authorsORDER BY lastName DESC
STRUCTURED QUERYLANGUAGE
• BASIC SQL QUERY- MIXTURE OF ALL CLAUSES :-• SELECT isbn, title, editionNumber, copyright, price
FROM titles WHERE title LIKE ‘%How to Program’ORDER BY title ASC
STRUCTURED QUERYLANGUAGE
• BASIC SQL QUERY- INSERT DATA INTO TABLE :-• Insert a new record into a table
• INSERT INTO tableName ( fieldName1, … , fieldNameN ) VALUES ( value1, … , valueN )
• INSERT INTO authors ( firstName, lastName ) VALUES ( ‘Sue’, ‘Smith’ )
STRUCTURED QUERYLANGUAGE
• BASIC SQL QUERY- UPDATE DATA IN TABLE :-• Modify data in a table• UPDATE tableName SET fieldName1 = value1, … , fieldNameN = valueN
WHERE criteria• UPDATE authors SET lastName = ‘Jones’ WHERE lastName = ‘Smith’ AND firstName = ‘Sue’
STRUCTURED QUERYLANGUAGE
• BASIC SQL QUERY- DELETE DATA FROM TABLE :-• Remove data from a table• DELETE FROM tableName WHERE criteria • DELETE FROM authors WHERE lastName = ‘Jones’ AND firstName = ‘Sue’
CREATING TABLE IN SQL• CREATE TABLE Books• (• Title CHAR(60),• ISBN CHAR(13),• Publisher_Id CHAR(5),• URL CHAR(80),• Price DECIMAL(6,2)• );
TYPICAL USES OF JDBC• (1) Use JDBC in both applications and applets.
• (2) Provides an interface to Relational Data Sources / Databases.
• (3) Provides the means for executing SQL statements to access and operate on a relational database.