CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.

Slides:



Advertisements
Similar presentations
Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Advertisements

 2003 Prentice Hall, Inc. All rights reserved. Chapter 22 – Database: SQL, MySQL, DBI and ADO.NET Outline 22.1 Introduction 22.2 Relational Database Model.
 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
Concepts of Database Management Sixth Edition
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Exercise SELECT authorID, lastName FROM authors AuthorID FirstName
JAVA JDBC JAVA JDBC Java Database Programming Lamiaa Said.
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 11. DATABASE CONNECTIVITY IN JAVA JDBC Programming JDBC (Java Database Connectivity) is the specification of a.
Lab: JDBC 1 Computer Engineering Lab III v Objective –to give some background on JDBC to help with the lab exercises , Semester 1,
Introduction to JDBC (Java Database Connectivity).
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. –
CSCI 6962: Server-side Design and Programming
Java Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
JDBC Java Database Connectivity. What is an RDBMS? Relational database management system. There are other kinds of DBMS. Access is a GUI on a JET RBDMS.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 25 – Database: SQL, ADO and RDS Outline 25.1Introduction 25.2Relational Database Model 25.3Relational.
ASP.NET Programming with C# and SQL Server First Edition
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
Jaeki Song JAVA Lecture 11 Java Database Connectivity.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
Database Programming in Java Corresponds with Chapter 32, 33.
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
A CCESSING D ATABASES WITH JDBC CH 24 C S 442: A DVANCED J AVA P ROGRAMMING.
 2003 Prentice Hall, Inc. All rights reserved. 1 Java Database Connectivity with JDBC TM.
Introduction to SQL Steve Perry
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 MySQL and JDBC.
Database: SQL and MySQL
1 Databases November 15, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg. Published.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
Relational Databases Database Driven Applications Retrieving Data Changing Data Analysing Data What is a DBMS An application that holds the data manages.
Concepts of Database Management Seventh Edition
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Tutorial 9 Using Action Queries and Advanced Table Relationships.
Presentation On How To Create Connection To A Database.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
 2005 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
A CCESSING D ATABASES WITH JDBC CH 24 C S 442: A DVANCED J AVA P ROGRAMMING.
DataBases and SQL INFSY 547 Spring Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 22 - SQL, MySQL, DBI and ADO Outline 22.1 Introduction 22.2 Relational Database Model 22.3 Relational.
Planning & Creating a Database By Ms. Naira Microsoft Access.
INTRODUCTION TO ACCESS. OBJECTIVES  Define the terms field, record, table, relational database, primary key, and foreign key  Create a blank database.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
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.
Physical Layer of a Repository. March 6, 2009 Agenda – What is a Repository? –What is meant by Physical Layer? –Data Source, Connection Pool, Tables and.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
ORDER BY Clause The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of.
INTRODUCTION TO DATABASES (MICROSOFT ACCESS)
JDBC Database Management Database connectivity
Database Programming in Java
 2012 Pearson Education, Inc. All rights reserved.
Accessing Databases with JDBC
JDBC.
Chapter 22 - SQL, MySQL, DBI and ADO
Lecture 11 Database Connection
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC

Introduction A _________ is an organized collection of data. A database management system (DBMS) is software that stores and organizes data in a special format. The most popular type of database is a relational database where data are stored in related _______. Popular relational database management systems (RDBMSs) include Access, Oracle, DB2, and MySQL. SQL (structured ______ language) is the standard RDBMS language for manipulating data. Java communicates with RDBMSs using the ____ API and drivers that implement it to a given database.

Relational Databases A relational database is a logical representation of data that allows data access w/o consideration of the __________ structure of the data. Data are stored in tables. The table represents a particular entity (Employee). Columns represent the _________ of an entity (ssn). A ________ represents a specific instance of an entity (employee John Doe). A primary ___ for a table is a column (field), or group of columns, that uniquely identifies a row (record). A ________ key is a column in one table that is a primary key in another related table.

The books Database Four tables: authors authorID, firstName, lastName publishers publisherID, publisherName titles isbn, title, editionNumber, copyright, publisherID, imageFile, price authorISBN authorID, isbn ______-relationship diagram ERD authors authorID firstName lastName authorISBN authorID isbn titles isbn title editionNumber copyright publisherID imageFile price publishers publisherID publisherName 1 n n 1

SELECT SELECT * FROM titles (select all _______ from titles) SELECT isbn, title, price FROM titles (only certain columns) SELECT * FROM titles WHERE copyright > 2000 (only certain ______) SELECT * FROM authors WHERE lastname LIKE ‘D%’ (last name starts with D) SELECT * FROM authors ORDER BY lastName, firstName (sort ___________ by default) SELECT isbn, title, price FROM titles WHERE price < 20 ORDER BY price DESC

INNER JOIN SELECT firstName, lastName, isbn FROM authors INNER JOIN authorISBN ON authors.authorID = authorISBN.authorID ORDER BY lastName, firstName This SQL statement lists the authors with their ISBNs SELECT determines the __________ FROM and INNER JOIN determines the two _______ ON specifies the common columns ORDER BY specifies sorting

INSERT, UPDATE, DELETE Insert a row in a table INSERT INTO authors (firstName, lastName) VALUES ( ‘Sue’, ‘Smith’ ) Update a row in a table UPDATE authors SET lastName = ‘Jones’ WHERE lastName = ‘Smith’ AND firstName = ‘Sue’ Delete a row in a table DELETE FROM authors WHERE authorID = 5

8 Using JDBC The four basic steps involved with using JDBC to connect to a database are: Load the appropriate JDBC driver Request a connection to the database Send SQL to the database Process results, if appropriate See /21/jdbc.html for more information. /21/jdbc.html

9 DisplayAuthors.java I Import package sql import java.sql.*; Identify driver class JdbcOdbcDriver static final String JDBC_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver"; Identify database file (books.mdb) static final String DATABASE_URL = “jdbc:odbc:books”; “jdbc:odbc:books” contains the communication ___________ ( jdbc ), subprotocol ( odbc ), and database name ( books )

10 DisplayAuthors.java II Create a Connection object to connect the Java program to the ___________ private Connection connection = DriverManager.getConnection( DATABASE_URL ); Set the location of the database with the property name and value System.setProperty( “odbc.system.home”, “C:/” );

11 DisplayAuthors.java III Get the specified Class object ( JdbcOdbcDriver ) Class.forName( JDBC_DRIVER ); Create a Statement object for submitting _______ statements to the database private Statement statement = connection.createStatement(); Execute an SQL statement and store results in a ResultSet object. ResultSet resultSet = statement.executeQuery( “SELECT * FROM authors” );

12 Setting Up ODBC Data Sources Open Microsoft Windows Control Panel. Double-click the Administrative Tools icon. Double-click on the Data Sources (ODBC) icon. Select the User DSN tab. To define a new data source for a currently installed driver, click Add. Complete the dialog boxes. Select Microsoft Access Driver, Finish Enter a Data Source Name (such as “books”) Click Select… and select the database, click OK