1 Design patterns Lecture 4. 2 Three Important skills Understanding OO methodology Mastering Java language constructs Recognizing common problems and.

Slides:



Advertisements
Similar presentations
Introduction to Structured Query Language (SQL)
Advertisements

Advanced Java Class Java Database Connectivity (JDBC)
Distributed Application Development B. Ramamurthy.
Introduction to Structured Query Language (SQL)
1 JDBC Java Database Connectivity. 2 c.pdf
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
Introduction to Structured Query Language (SQL)
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
Java Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Database Lecture # 1 By Ubaid Ullah.
ASP.NET Programming with C# and SQL Server First Edition
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
Announcements Read JDBC Project Step 5, due Monday.
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 What is database 2? What is normalization? What is SQL? What is transaction?
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Java Database Connectivity (JDBC). Topics 1. The Vendor Variation Problem 2. SQL and Versions of JDBC 3. Creating an ODBC Data Source 4. Simple Database.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
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.
Visual Programing SQL Overview Section 1.
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC Session 14.
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 8: Applications Programming for Relational Databases Instructor’s.
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
1 JDBC – Java Database Connectivity CS , Spring 2010.
In the Name Of Almighty Allah. Java Application Connection To Mysql Created by Hasibullah (Sahibzada) Kabul Computer Science Faculty Afghanistan.
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.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
JDBC. Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
Database: JDBC Overview
DEPTT. OF COMP. SC & APPLICATIONS
Lec - 14.
JDBC Database Management Database connectivity
JDBC – Java Database Connectivity
Database JDBC Overview CS Programming Languages for Web Applications
JDBC.
Chapter 8 Working with Databases and MySQL
Interacting with Database
Java Database Connectivity
Java API for Database Connectivity
Presentation transcript:

1 Design patterns Lecture 4

2 Three Important skills Understanding OO methodology Mastering Java language constructs Recognizing common problems and applying an appropriate design pattern to solve them

3 Design patterns… A design pattern is a proposed solution to common design problems May describe a high level architecture of software… …or in detail with classes and methods. …or somewhere in between By becoming familiar with well-known patterns, you may produce more flexible and robust code.

4 Patterns vs frameworks The book discriminates between “design pattern” and “framework”. A design pattern is an abstraction you read about A framework is collections of reusable classes that implement some design pattern. Typically you extend the provided framework types, making the subtypes context specific

5 Example of pattern vs framework The observer design pattern is in Java core API implemented by the framework of an Observer interface and the Observable class.

6 Model-View-Controller

7 MVC benefits Change user interface (View) without impacting algorithms and business rules in the core (model) of the application. Rework the model without changing anything in the user interface. View and Model are decoupled.

8 Assignment 2b

9 Multiple views

10 Other design patterns Object creation Singletons Enforces one instance but many references to the instance. Object factory Decides dynamically which subclass to instantiate

11 Other design patterns Structural patterns Adapter E.g. WindowAdapter class implements the exhaustive WindowListener interface with default (empty) handlers. Façade When you have a class with an interface that can’t be changed and doesn’t fit your context. Make a Façade class that perform required mappings between existing interface and desired interface.

12 And numerous other patterns We may eventually come back to this topic if we have time left in the end of June.

13 Databases Lecture 4

14 “The book” Please read chapter 9 Skim read and focus on interesting areas that may relate to assignment 2. If you haven’t taken the database class (which we assume you haven’t), you should read this chapter in order to get a grip on different aspects of database design and implementation. You are not supposed to become an expert, but at least learn the basics, and get inspired by good practices that is mentioned in the book.

15 Acronyms RDBM – Relational database management (system) E.g. DB2, Oracle, Sybase, MS SQL Server… JDBC - Java database connectivity Is part of the J2SE platform Provides a bridge between a Java program and an RDBM system usually running on native operating system.

16 Acronyms … SQL – Structured query language is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems. SQL statements are used to retrieve and update data in a database. May have slightly different flavors in different RDBM systems.

17 PostGresQL Syntax You need to know a little PostGresQL syntax to set up your DB and use JDBC SQL to Java type mappings: see p. 623, figure 9-6 Documentation: Look at \h and \? for command syntax At the command line: psql pg_dump man psql

18 Common Table Commands CREATE TABLE table_name ( column_name1 column_type1, column_name2 column_type2, etc.); Can also specify a DEFAULT value, or other constraints like NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, etc. \dt (shows tables) \d table_name (describes that table) DROP TABLE table_name; ALTER TABLE table_name RENAME TO new_table_name;

19 Common Column Commands ALTER TABLE table_name ADD column_name column_type [constraints]; ALTER column_name SET DEFAULT value; ALTER column_name DROP DEFAULT; RENAME old_column_name TO new_column_name;

20 Common Row Commands INSERT INTO table_name values (42, 3, ‘foo’) INSERT INTO table_name (col2_name, col3_name) values (3, ‘foo’); UPDATE table_name SET col = expression [WHERE condition]; DELETE FROM table_name [WHERE condition];

21 Select SELECT LastName,FirstName FROM Persons

22 Select SELECT * FROM Persons WHERE City='Sandnes'

23 Common “\” Commands \? Shows all “\” commands \h shows help menu \h COMMAND_NAME shows help for a specific command \q quits psql program

24 JDBC Driver types Type 1. JDBC-ODBC bridge (inefficient) Type 2. Mostly implemented in native code (C) with JNI (Java Native Interfaces) to bridge between Java and the native code (C). Most efficient driver if all classes using db are on the db host Type 3. Like type 2, but the user accesses the db over TCP/IP. Most efficient driver if not all classes using db are on the db host. Type 4. Like type 3 but pure Java implementation, and therefore platform independent. A type 4 driver for your first project is linked from the assignment page.

25 Loading the driver and getting the db-connection Class.forName(“org.postgresql.Driver”) A call to forName("X") causes the class named X to be initialized. In this case the database driver will be loaded into memory. This will load the driver, and while loading, the driver will automatically register itself with JDBC. Connection db = DriverManager.getConnection(url, username, password);

26 Statements java.sql.Statement is the most common way to query the db. The PreparedStatement class may be used for precompiled SQL queries.

27 Execution of SQL by Statement int Statement.executeUpdate(String sql); Returns number rows affected Good for INSERT, UPDATE, and DELETE ResultSet Statement.executeQuery(String sql); Returns a ResultSet Good for SELECT

28 ResultSet Contains the results of a select statement. Remember Before reading any values, you must call next(). You must close a ResultSet by calling close() once you have finished using it. Once you make another query with the Statement used to create a ResultSet, the currently open ResultSet instance is closed automatically.

29 Basic use of java.sql 1. Load driver class 2. Get connection 3. Get statement 4. Ask statement to execute sql string 5. Process results if needed 6. Close Statement and Connection