Dr. Magdi AMER Unit 2 Introduction to Database. Intro Many programs need to save information on disk. The role of DB system is to provide a layer of abstraction.

Slides:



Advertisements
Similar presentations
Database programming in Java An introduction to Java Database Connectivity (JDBC)
Advertisements

NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
The SQL Language Presented by Reggie James, Isel Liunoras, and Chris Rollins.
15-Jun-15 JDBC. JDBC is a Sun trademark It is often taken to stand for Java Database Connectivity Java is very standardized, but there are many versions.
1 JDBC Java Database Connectivity. 2 c.pdf
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
Java MS Access database connectivity Follow these steps: 1)Go to the start->Control Panel->Administrative Tools- > data sources. 2)Click Add button and.
CIS 270—App Dev II Big Java Chapter 22 Relational Databases.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
Overview of JDBC and Pro*C 1 Overview of JDBC,Pro*C and Oracle connectivity on Omega CSE 5330 – Database Systems.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 8 Object Oriented Programming in Java Advanced Topics Java Database.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Georgia Institute of Technology Making Text for the Web part 5 Barb Ericson Georgia Institute of Technology March 2006.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Overview of JDBC and Pro*C 1 CSE 5330 – Database Systems.
JDBC  The JDBC (Java Database Connectivity) API helps a Java program to access a database in a standard way  JDBC is a specification that tells the.
1 JDBC Aum Amriteshwaryai Namah. 2 2 JDBC – Java DataBase Connectivity.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
Chapter 8 Databases.
JDBC – Java Database Concentricity
Chapter 25 Databases. Chapter Scope Database concepts Tables and queries SQL statements Managing data in a database Java Foundations, 3rd Edition, Lewis/DePasquale/Chase25.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Web Design & Development 1 Lec Web Design & Development 2 More on JDBC.
JDBC Database Programming in Java Prepared by., Mrs.S.Amudha AP/SWE.
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
Session 30 Basics of JDBC. Java Simplified / Session 30 / 2 of 33 Review A Swing menu consists of a menubar, menuitems and menus. Trees are used to depict.
Li Tak Sing COMPS311F. Database programming JDBC (Java Database Connectivity) Java version of ODBC (Open Database Connectivity) ODBC provides a standard.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
EXAMPLE I An application showing JDBC access to Cloudscape.
Connecting to MySQL using Java By:. – Required to use Java.sql so that we can use Connection and Queries using strings. – Javax.swing.* needed for components.
CSI 3125, Preliminaries, page 1 JDBC. CSI 3125, Preliminaries, page 2 JDBC JDBC stands for Java Database Connectivity, which is a standard Java API (application.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
Web Programming Assistant Professor Xiaozhong Liu
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
JDBC.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
MySQL root 암호 $ mysqladmin -u root -p password new-password $ mysql -u root mysql mysql> update user set password = password('new-password') where user.
Lec - 14.
JDBC 15-Apr-18.
JDBC – Java Database Connectivity
CS320 Web and Internet Programming Database Access with JDBC
JDBC 21-Aug-18.
HW#4 Making Simple BBS Using JDBC
JDBC.
Prof: Dr. Shu-Ching Chen TA: Sheng Guan
“Introduction To Database and SQL”
JDBC 15-Nov-18.
Interacting with Database
Super Market Management
Bolat Azamat, Kim Dongmin
JDBC Example.
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Dr. Magdi AMER Unit 2 Introduction to Database

Intro Many programs need to save information on disk. The role of DB system is to provide a layer of abstraction between the program and the database (Save, read, update, delete). First system was released in 1960 by IBM called Information Management System (IMS). It was based on the hierarchical model. 2Dr. Magdi Amer

Intro (Cnt) Hierarchical model has several drawbacks (query, update) Edgar Codd, a British mathematician, created the relational model in 1970, where information is saved into tables. SEQUEL, which was later named SQL (but still pronounced sequel), was developed, based on relational algebra to allow users to define, query and update the database in a standardized way. Codd, with the collaboration of Chris Date, formed their own consulting company and continued to develop the relational standard. 3Dr. Magdi Amer

First Normal Form 4 Project codeDescriptionEmployee name Emp #GradeCost/ hour MonthAllocated Time Prj406E-CommerceSmith127A13012/9950 hour 1/ hour Mark431A22512/9920 hour 1/ hour Tom121A13012/9920 hour 1/ hour Prj012PayrollJack114A13012/9922 hour 1/ hour Green323A22512/9926 hour 1/ hour Dr. Magdi Amer

First Normal Form Each record contains the same number of columns. Each column contain 1 and only 1 value. No information is saved in the order of the records. Each Record must have a key 5 Project code DescriptionEmployee nameEmp #GradeCost/ hourMonthAllocated Time Prj406E-CommerceSmith127A13012/9950 hour Prj406E-CommerceSmith127A1301/ hour Prj406E-CommerceMark431A22512/9920 hour Prj406E-CommerceMark431A2251/ hour Prj406E-CommerceTom121A13012/9920 hour Prj406E-CommerceTom121A1301/ hour Prj012PayrollJack114A13012/9922 hour Prj012PayrollJack114A1301/ hour Prj012PayrollGreen323A22512/9926 hour Prj012PayrollGreen323A2251/ hour Dr. Magdi Amer

Second Normal Form Each column is a function of the entire key, not part of the key. 6 Project code DescriptionEmployee nameEmp #GradeCost/ hourMonthAllocated Time Prj406E-CommerceSmith127A13012/9950 hour Prj406E-CommerceSmith127A1301/ hour Prj406E-CommerceMark431A22512/9920 hour Prj406E-CommerceMark431A2251/ hour Prj406E-CommerceTom121A13012/9920 hour Prj406E-CommerceTom121A1301/ hour Prj012PayrollJack114A13012/9922 hour Prj012PayrollJack114A1301/ hour Prj012PayrollGreen323A22512/9926 hour Prj012PayrollGreen323A2251/ hour Dr. Magdi Amer

Second Normal Form Each column is a function of the entire key, not part of the key. 7Dr. Magdi Amer

Third Normal Form Each column is directly a function of the key. Third normal form is violated when a non-key field is a fact about another non-key field 8Dr. Magdi Amer

Normalization What you need to remember: Normalization is needed: – To save space – To prevent data inconsistency (2 rows supposedly containing the same info but in reality there is a difference in the information stored) – To facilitate update 9Dr. Magdi Amer Student_idStudent_nameCampus_nameCampus_location S101AmalFemale-campusAbedeya S102NohaFemale-campusAbedeya S103HebaFemale-campusDowntown S104MonaFemale-campusDowntown Example of inconsistent data due to lack of normalization

Introduction to SQL 10Dr. Magdi Amer

Introduction to SQL 11Dr. Magdi Amer

Introduction to SQL 12Dr. Magdi Amer

Getting data from normalized tables 13Dr. Magdi Amer Select Employee.Employee_number, Employee.Employee_name, Grade_data.Grade, Grade_data.Cost_per_hour From Employee inner join Grade_data on Grade_data.Grade = Employee.Grade Employee Grade_Data This is done by rebuilding the original table before normalization

Accessing Oracle Express Dr. Magdi Amer14

Dr. Magdi Amer15 Accessing Oracle Express

Dr. Magdi Amer16

Dr. Magdi Amer17 SQL Dev

Dr. Magdi Amer18 SQL Dev

Dr. Magdi Amer19 SQL Dev

Dr. Magdi Amer20 SQL Dev

Dr. Magdi Amer21 SQL Dev

22Dr. Magdi Amer Creating NetBeans App

23Dr. Magdi Amer Making a Connection

24Dr. Magdi Amer Accessing the data from Java

25Dr. Magdi Amer Accessing the data from Java

Making a query 26Dr. Magdi Amer import java.io.*; import java.sql.*; public class DatabaseTest{ public static void main(String[] args){ Connection con= null; Statement s = null; try { con = DatabaseManager.getConnection(); s = con.createStatement(); String query = " SELECT firstName, lastName, sin FROM Employee" ; System.out.println(query); ResultSet result = s.executeQuery(query); String firstName, lastName, sin;

Making a query 27Dr. Magdi Amer while(result.next()) { firstName = result.getString("firstName"); lastName = result.getString("lastName"); sin = result.getString("sin"); System.out.println("first Name = "+firstName+"last Name="+lastName+ "sin ="+sin); }//end while }//end try catch(Exception ex) { System.out.println(ex); } finally { if(con != null) try { con.close(); } catch(Exception ex) { ex.printStackTrace(); } } } // end main } // end class

28Dr. Magdi Amer Writing in a table

29Dr. Magdi Amer Writing in a table

30Dr. Magdi Amer Writing in a table

31Dr. Magdi Amer Writing in a table

32Dr. Magdi Amer Writing in a table try { con = DatabaseManager.getConnection(); s = con.createStatement(); String sql = "create table Data (name varchar (32), id integer);"; int result = s.executeUpdate(sql); sql = "insert into Data (name, id) values ('Tom', 123 );"; result = s.executeUpdate(sql); sql = "insert into Data (name, id) values ('Mike', 123 );"; result = s.executeUpdate(sql); sql = "UPDATE Data SET Data.id = 121 WHERE (Data.name='Mike');"; result = s.executeUpdate(sql); }

33Dr. Magdi Amer Writing in a table catch(Exception ex) { System.out.println(ex); } finally { try { s.close(); con.close(); } catch(Exception e) { System.out.println(e);} } } }

Dr. Magdi Amer34 SQL Injection Consider the following code Normally this code will return the information if the password is correct What will happen if the user enters ' or '1'='1 The executed query will be SELECT firstName, lastName, sin FROM Employee where password = ' ' or '1'='1‘ The previous query result will always be true  hacker can access any record ……… String pass = // read from GUI or web String query = " SELECT firstName, lastName, sin FROM Employee where password = ' "+pass+ " ' "; ResultSet result = s.executeQuery(query); ……………

35Dr. Magdi Amer public void Save() { String query = "INSERT INTO LANGUAGE ( ID, NAME) VALUES (?, ?)"; PreparedStatement s = null; Connection con = null; String url=”…”; try { Connection con = DatabaseManager.getConnection(); s = con.prepareStatement(query); s.setString(2, ""+getName()); //reads it from GUI or web s.setString(1, ""+getId()); // reads it from GUI or web int result = s.executeUpdate(); } catch (SQLException e) { System.err.println(e); } finally { try{ if(s !=null) s.close(); if(con != null) con.close(); } catch(Exception e1) { System.err.println(e1); } } } Prepared Statement

36Dr. Magdi Amer Example

37Dr. Magdi Amer From Java to DB

38Dr. Magdi Amer Saving: Tire

39Dr. Magdi Amer Saving : Motor

40Dr. Magdi Amer Saving : Motor

41Dr. Magdi Amer Saving : Car

42Dr. Magdi Amer Saving : Car

43Dr. Magdi Amer Example: Saving

44Dr. Magdi Amer Loading: Motor

45Dr. Magdi Amer Loading: Tire

46Dr. Magdi Amer Loading: Car

47Dr. Magdi Amer Example: Loading