CS 160: Software Engineering October 6 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.
Advertisements

A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
CS 185C/286: The History of Computing October 31 Class Meeting Department of Computer Science San Jose State University Fall 2011 Instructor: Ron Mak
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
CS 160: Software Engineering August 27 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
CS 46B: Introduction to Data Structures July 30 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
CS 160: Software Engineering November 10 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
Web Application Development. Define ER model in QSEE Generate SQL Create Database mySQL Write Script to use TableEditor class Process to create A simple.
Web Application Development. Tools to create a simple web- editable database QSEE MySQL (or PHPMyAdmin) PHP TableEditor.
CS 160: Software Engineering October 8 Class Meeting
CS 157B: Database Management Systems II January 30 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
Information Systems Today (©2006 Prentice Hall) MySQL 1CS3754 Class Note #8, Is an open-source relational database management system 2.Is fast and.
CS 157B: Database Management Systems II April 29 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
CMPE 226 Database Systems September 16 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CS 235: User Interface Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 174: Web Programming September 23 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming September 21 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 157B: Database Management Systems II February 6 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
CS 157B: Database Management Systems II February 4 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
CS 174: Web Programming September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 157B: Database Management Systems II January 28 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
CS 235: User Interface Design September 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 160: Software Engineering October 1 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 160: Software Engineering October 15 Class Meeting
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Chapter 25 Databases. Chapter Scope Database concepts Tables and queries SQL statements Managing data in a database Java Foundations, 3rd Edition, Lewis/DePasquale/Chase25.
CMPE 226 Database Systems September 23 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CS 157B: Database Management Systems II April 3 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
CMPE 226 Database Systems October 7 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
1 COP 4710 Databases Fall, 2000 Today’s Topic Chapter 7: SQL David A. Gaitros October 9th, 2000 Department of Computer Science.
CS 153: Concepts of Compiler Design October 7 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design October 10 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming September 28 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 157B: Database Management Systems II February 20 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
CS 174: Web Programming October 12 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design October 21 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming October 14 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 160: Software Engineering December 10 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Task #1 Create a relational database on computers in computer classroom 308, using MySQL server and any client. Create the same database, using MS Access.
CS 174: Web Programming November 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 157B: Database Management Systems II April 22 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
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.
Visual Database Creation with MySQL Workbench 도시정보시스템 설계
Databases and SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
CS 160 and CMPE/SE 131 Software Engineering March 10 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CS 160 and CMPE/SE 131 Software Engineering March 15 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
CS 157B: Database Management Systems II January 23 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
Database Programming Basic JDBC Programming Concepts.
CS320 Web and Internet Programming SQL and MySQL
CS 153: Concepts of Compiler Design October 5 Class Meeting
Session 4 PHP & MySQL.
CS 174: Server-Side Web Programming February 12 Class Meeting
CMPE 152: Compiler Design September 11/13 Lab
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
CMPE/SE 131 Software Engineering March 9 Class Meeting
CMPE 152: Compiler Design March 7/12 Lab
CMPE/SE 131 Software Engineering March 7 Class Meeting
Presentation transcript:

CS 160: Software Engineering October 6 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak 2 JDBC Example: Database Record Insert  Method executeUpdate() returns the number of records that were inserted. String insert = "INSERT INTO teacher (id, last, first)" + "VALUES (7088, 'Mak', 'Ron'), " + "(7090, 'Wilson', 'Ron') "; System.out.print(" Insert: "); int rowCount = stmt.executeUpdate(insert); System.out.println(rowCount + " new rows.");

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak 3 JDBC Example: Database Record Update String update = "UPDATE teacher" + "SET first = 'Ronald'" + "WHERE first = 'Ron'"; System.out.print(" Update: "); rowCount = stmt.executeUpdate(update); System.out.println(rowCount + " rows changed.");  Method executeUpdate() returns the number of records that were changed.

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak 4 JDBC Example: Database Record Update  In any WHERE clause, LIKE allows wild cards in the string pattern. % matches zero or more characters.  'Ron%' matches 'Ron' and 'Ronald’ _ matches any single character.  '_onald' matches 'Ronald' and 'Donald' String delete = "DELETE FROM teacher" + "WHERE first LIKE 'Ron%'"; System.out.print(" Delete: "); rowCount = stmt.executeUpdate(delete); System.out.println(rowCount + " rows removed."); Demo

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak 5 MySQL Workbench  Open-source version of some very expensive commercial database design and management tools (such as ERWin Data Modeler). Download from  Features Manage databases and database connections Edit, execute, and save SQL scripts Forward- and reverse-engineering  Generate a crow’s feet ER diagram from an existing database  Manually create an ER diagram  Automatically generate a database from the diagram

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak MySQL Workbench: Table Contents  Demo: View the contents of tables. The School2 database is a copy of the School database. _ 6

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak SQL to Create and Drop a Database  Examples to create:  Examples to drop: 7 CREATE DATABASE school3; CREATE DATABASE IF NOT EXISTS school3; DROP DATABASE school3; DROP DATABASE IF EXISTS school3;

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak CREATE TABLE class ( code INT PRIMARY KEY, teacher_id INT NOT NULL, subject VARCHAR(32) NOT NULL, room INT NOT NULL ); SQL to Create a Table  First we create a new database and connect to it:  Create the Class table: 8 CREATE DATABASE school3; USE school3; CodeTeacher_idSubjectRoom Data structures Java programming Compilers Software engineering Operating systems 109

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak SQL to Add Rows  Add rows to the Class table: 9 CodeTeacher_idSubjectRoom Data structures Java programming Compilers Software engineering Operating systems 109 INSERT INTO class (code, teacher_id, subject, room) VALUES (908, 7008, 'Data structures', 114), (926, 7003, 'Java programming', 101), (931, 7051, 'Compilers', 222), (951, 7012, 'Software engineering', 210), (978, 7012, 'Operating systems', 109);

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak SQL Script create_school.sql 10 DROP DATABASE IF EXISTS school3; CREATE DATABASE school3; USE school3; CREATE TABLE class ( codeINTPRIMARY KEY, teacher_id INT NOT NULL, subject VARCHAR(32)NOT NULL, room INT NOT NULL, ); INSERT INTO class (code, teacher_id, subject, room) VALUES(908, 7008, 'Data structures', 114), (926, 7003, 'Java programming', 101), (931, 7051, 'Compilers', 222), (951, 7012, 'Software engineering', 210), (978, 7012, 'Operating systems', 109);

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak SQL Script create_school.sql, cont’d 11 CREATE TABLE contact_info ( idINTPRIMARY KEY, _addressVARCHAR(32)NOT NULL ); INSERT INTO contact_info (id, _address) VALUES(1, (2, (3, (4, (5, (6, (7, (8, (9,

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak SQL Script create_school.sql, cont’d 12 CREATE TABLE teacher ( idINTPRIMARY KEY, lastVARCHAR(32)NOT NULL, firstVARCHAR(32)NOT NULL, contact_idINTREFERENCES contact_info(id) ); INSERT INTO teacher (id, last, first, contact_id) VALUES(7003, 'Rogers','Tom',6), (7008, 'Thompson','Art',7), (7012, 'Lane','John’,8), (7051, 'Flynn','Mabel',9);  Use the MySQL source command: mysql> source create_school.sql

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak MySQL Workbench: Table Contents  Demo: Add rows to tables.  Demo: Delete rows from tables. _ 13

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak MySQL Workbench: EER Diagrams  MySQL Workbench creates Extended ER (EER) diagrams.  Demo: View an existing diagram Save the diagram as a PDF. _ 14

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak MySQL Workbench: EER Diagrams, cont’d  MySQL Workbench can generate a new EER diagram by “reverse engineering” an existing database.  Demo: Generate a new EER diagram. _ 15

Computer Science Dept. Fall 2014: October 6 CS 160: Software Engineering © R. Mak MySQL Workbench: EER Diagrams, cont’d  Demo: Manually create a new EER diagram. Generate a new database from the EER diagram. _ 16