 2003 Prentice Hall, Inc. All rights reserved. 1 Java Database Connectivity with JDBC TM.

Slides:



Advertisements
Similar presentations
 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.
Advertisements

Lecture 9 Chapter 23: Java Database Connectivity with JDBC Outline 23.1 Introduction 23.2 Relational-Database Model 23.3 Relational Database Overview:
Java and Databases CS-328 Dick Steflik. Database Drivers Think of a database as just another device connected to your computer like other devices it has.
 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
1 Introduction to Web Application Introduction to Data Base.
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
CSE470 Software Engineering Fall Database Access through Java.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 23: Java Database Connectivity with JDBC Outline 23.1 Introduction 23.2 Relational-Database Model.
Web Application Deployment & JDBC CSC 667, Spring 2004 Dr. Ilmi Yoon.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 23: Java Database Connectivity with JDBC Outline 23.1 Introduction 23.2 Relational-Database Model.
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 Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
 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
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.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Pemrograman VisualMinggu …10… Page 1 MINGGU Ke Sepuluh Pemrograman Visual Pokok Bahasan: ADO.NET II Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 10: Database Application Programming Interface Xiang Lian The University of Texas – Pan American Edinburg,
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
Database: SQL and MySQL
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
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.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 23: Java Database Connectivity with JDBC Outline 23.1 Introduction 23.2 Relational-Database Model.
Database, SQL, and ADO.NET- Part 1 Session 11 Mata kuliah: M0874 – Programming II Tahun: 2010.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
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.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved. 2 Revised by Dr. T. Tran for CSI3140.
 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.
 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.
 2009 Pearson Education, Inc. All rights reserved Databases and LINQ to SQL.
Basics of JDBC Session 14.
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.
LINQ to DATABASE-2.  Creating the BooksDataContext  The code combines data from the three tables in the Books database and displays the relationships.
R EMAINING TOPICS IN JDBC Sagun Dhakhwa. O VERVIEW Introduction to JDBC API Types of JDBC Drivers Introduction to ODBC.
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.
Database, SQL and ADO.NET
Database Programming in Java
 2012 Pearson Education, Inc. All rights reserved.
Accessing Databases with JDBC
LINQ to DATABASE-2.
JDBC.
Databases Intro (from Deitel)
Chapter 8 Working with Databases and MySQL
Databases - בסיסי נתונים
Chapter 22 - SQL, MySQL, DBI and ADO
LINQ to DATABASE-2.
資料庫管理作業(一).
Introduction To Structured Query Language (SQL)
MySQL安裝&操作教學.
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

 2003 Prentice Hall, Inc. All rights reserved. 1 Java Database Connectivity with JDBC TM

 2003 Prentice Hall, Inc. All rights reserved. 2 Introduction Database –Collection of data DBMS –Database management system –Stores and organizes data SQL –Relational database –Structured Query Language

 2003 Prentice Hall, Inc. All rights reserved. 3 Introduction (Cont.) RDBMS –Relational database management system –Cloudscape JDBC –Java Database Connectivity –JDBC driver

 2003 Prentice Hall, Inc. All rights reserved Relational-Database Model Relational database –Table Rows, columns –Primary key Unique data SQL statement –Query

 2003 Prentice Hall, Inc. All rights reserved Relational-Database Model (Cont.) Fig Employee table sample data. NumberNameDepartmentSalaryLocation 23603Jones New Jersey 24568Kerwin New Jersey 34589Larson Los Angeles 35761Myers Orlando 47132Neumann New Jersey 78321Stephens Orlando Row ColumnPrimary key

 2003 Prentice Hall, Inc. All rights reserved Relational-Database Model (Cont.) Fig. 23.2Result of selecting distinct Department and Location data from the Employee table. DepartmentLocation 413New Jersey 611Orlando 642Los Angeles

 2003 Prentice Hall, Inc. All rights reserved Relational Database Overview: The books Database Sample books database –Four tables authors, publishers, authorISBN and titles –Relationships among the tables

 2003 Prentice Hall, Inc. All rights reserved Relational Database Overview: The books Database (Cont.)

 2003 Prentice Hall, Inc. All rights reserved Relational Database Overview: The books Database (Cont.) publisherID publisherName 1 Prentice Hall 2 Prentice Hall PTG Fig Data from the publishers table.

 2003 Prentice Hall, Inc. All rights reserved Relational Database Overview: The books Database (Cont.)

 2003 Prentice Hall, Inc. All rights reserved Relational Database Overview: The books Database (Cont.)

 2003 Prentice Hall, Inc. All rights reserved Relational Database Overview: The books Database (Cont.) authorID isbn authorID isbn Fig Sample data from the authorISBN table of books.

 2003 Prentice Hall, Inc. All rights reserved Relational Database Overview: The books Database (Cont.) Fig Table relationships in books. authorISBN authorID isbn authors authorID firstName lastName publishers publisherID publisherName titles isbn title editionNumber copyright publisherID imageFile price 1  1  1 

 2003 Prentice Hall, Inc. All rights reserved SQL SQL overview SQL keywords SQL keyword Description SELECT Retrieves data from one or more tables. FROM Tables involved in the query. Required in every SELECT. WHERE Criteria for selection that determine the rows to be retrieved, deleted or updated. GROUP BY Criteria for grouping rows. ORDER BY Criteria for ordering rows. INNER JOIN Merge rows from multiple tables. INSERT Insert rows into a specified table. UPDATE Update rows in a specified table. DELETE Delete rows from a specified table. Fig SQL query keywords.

 2003 Prentice Hall, Inc. All rights reserved Basic SELECT Query Simplest form of a SELECT query –SELECT * FROM tableName SELECT * FROM authors Select specific fields from a table –SELECT authorID, lastName FROM authors

 2003 Prentice Hall, Inc. All rights reserved WHERE Clause specify the selection criteria –SELECT columnName1, columnName2, … FROM tableName WHERE criteria SELECT title, editionNumber, copyright FROM titles WHERE copyright > 2000 WHERE clause condition operators –, =, =, <> –LIKE wildcard characters % and _

 2003 Prentice Hall, Inc. All rights reserved WHERE Clause (Cont.)

 2003 Prentice Hall, Inc. All rights reserved WHERE Clause (Cont.) SELECT authorID, firstName, lastName FROM authors WHERE lastName LIKE ‘D%’

 2003 Prentice Hall, Inc. All rights reserved WHERE Clause (Cont.) SELECT authorID, firstName, lastName FROM authors WHERE lastName LIKE ‘_i%’

 2003 Prentice Hall, Inc. All rights reserved ORDER BY Clause Optional ORDER BY clause –SELECT columnName1, columnName2, … FROM tableName ORDER BY column ASC –SELECT columnName1, columnName2, … FROM tableName ORDER BY column DESC ORDER BY multiple fields –ORDER BY column1 sortingOrder, column2 sortingOrder, … Combine the WHERE and ORDER BY clauses

 2003 Prentice Hall, Inc. All rights reserved ORDER BY Clause (Cont.) SELECT authorID, firstName, lastName FROM authors ORDER BY lastName ASC authorID firstName lastName 2 Paul Deitel 1 Harvey Deitel 3 Tem Nieto 4 Sean Santry Fig Sample data from table authors in ascending order by lastName.

 2003 Prentice Hall, Inc. All rights reserved ORDER BY Clause (Cont.) SELECT authorID, firstName, lastName FROM authors ORDER BY lastName DESC authorID firstName lastName 4 Sean Santry 3 Tem Nieto 2 Paul Deitel 1 Harvey Deitel Fig Sample data from table authors in descending order by lastName.

 2003 Prentice Hall, Inc. All rights reserved ORDER BY Clause (Cont.) SELECT authorID, firstName, lastName FROM authors ORDER BY lastName, firstName authorID firstName lastName 1 Harvey Deitel 2 Paul Deitel 3 Tem Nieto 4 Sean Santry Fig Sample author data from table authors in ascending order by lastName and by firstName.

 2003 Prentice Hall, Inc. All rights reserved ORDER BY Clause (Cont.) SELECT isbn, title, editionNumber, copyright, price FROM titles WHERE title LIKE ‘%How to Program’ ORDER BY title ASC

 2003 Prentice Hall, Inc. All rights reserved Merging Data from Multiple Tables: Joining Split related data into separate tables Join the tables –Merge data from multiple tables into a single view –INNER JOIN SELECT columnName1, columnName2, … FROM table1 INNER JOIN table2 ON table1.columnName = table2.column2Name SELECT firstName, lastName, isbn FROM authors, authorISBN INNER JOIN authorISBN ON authors.authorID = authorISBN.authorID ORDER BY lastName, firstName

 2003 Prentice Hall, Inc. All rights reserved Merging Data from Multiple Tables: Joining (Cont.)

 2003 Prentice Hall, Inc. All rights reserved INSERT Statement Insert a row into a table –INSERT INTO tableName ( columnName1, …, columnNameN ) VALUES ( value1, …, valueN ) INSERT INTO authors ( firstName, lastName ) VALUES ( ‘Sue’, ‘Smith’ ) authorID firstName lastName 1 Harvey Deitel 2 Paul Deitel 3 Tem Nieto 4 Sean Santry 5 Sue Smith Fig Sample data from table Authors after an INSERT operation.

 2003 Prentice Hall, Inc. All rights reserved UPDATE Statement Modify data in a table –UPDATE tableName SET columnName1 = value1, …, columnNameN = valueN WHERE criteria UPDATE authors SET lastName = ‘Jones’ WHERE lastName = ‘Smith’ AND firstName = ‘Sue’ authorID firstName lastName 1 Harvey Deitel 2 Paul Deitel 3 Tem Nieto 4 Sean Santry 5 Sue Jones Fig Sample data from table authors after an UPDATE operation.

 2003 Prentice Hall, Inc. All rights reserved DELETE Statement Remove data from a table –DELETE FROM tableName WHERE criteria DELETE FROM authors WHERE lastName = ‘Jones’ AND firstName = ‘Sue’ authorID firstName lastName 1 Harvey Deitel 2 Paul Deitel 3 Tem Nieto 4 Sean Santry Fig Sample data from table authors after a DELETE operation.

 2003 Prentice Hall, Inc. All rights reserved Manipulating Databases with JDBC Connect to a database Query the database Display the results of the query

 2003 Prentice Hall, Inc. All rights reserved Connecting to and Querying a JDBC Data Source (Cont.) Type Description 1 TheJDBC-to-ODBC bridge driver connects Java programs to Microsoft ODBC (Open Database Connectivity) data sources. The Java 2 Software Development Kit from Sun Microsystems, Inc. includes the JDBC-to-ODBC bridge driver ( sun.jdbc.odbc.JdbcOdbcDriver ). This driver typically requires the ODBC driver to be installed on the client computer and normally requires configuration of the ODBC data source. The bridge driver was introduced primarily for development purposes and should not be used for production applications. 2 Native-API, partly Java drivers enable JDBC programs to use database-specific APIs (normally written in C or C++) that allow client programs to access databases via the Java Native Interface. This driver type translates JDBC into database-specific code. Type 2 drivers were introduced for reasons similar to the Type 1 ODBC bridge driver. 3 JDBC-Net pure Java drivers take JDBC requests and translate them into a network protocol that is not database specific. These requests are sent to a server, which translates the database requests into a database-specific protocol. 4 Native-protocol pure Java drivers convert JDBC requests to database-specific network protocols, so that Java programs can connect directly to a database. Fig JDBC driver types.

 2003 Prentice Hall, Inc. All rights reserved. 32 JDBC-ODBC Bridge( 補充 ) From JNetDirect ( Download JNetDirect driver from 執行該安裝檔案

 2003 Prentice Hall, Inc. All rights reserved. 33 ODBC Data Source Name Setup 控制台 -> 系統管理工具 -> 資料來源 (ODBC) 捷徑 按 “ 系統資料來源名稱 ” Tab 按 “ 新增 ”

 2003 Prentice Hall, Inc. All rights reserved. 34 ODBC Data Source Name Setup 選擇 Microsoft Access Driver (*.mdb) 按 “ 完成 ”

 2003 Prentice Hall, Inc. All rights reserved. 35 ODBC Data Source Name Setup 設定 “ 資料來源名稱 ” 為 MyDSN 按 “ 選擇 ” 去選取 Access 資料庫檔案 按 “ 進階 ”

 2003 Prentice Hall, Inc. All rights reserved. 36 ODBC Data Source Name Setup 輸入 “ 登入名稱 ” 及 “ 密碼 ” 按 “ 確定 ” ( 三次 )

 2003 Prentice Hall, Inc. All rights reserved. 37 範例程式 copy JData2_0.jar from C:\Program Files\JNetDirect\JDataConnect\JARS\ to C:\Program Files\JNetDirect\JDataConnect\Examples javac ExampleApplication.java java -classpath.;./JData2_0.jar ExampleApplication

 2003 Prentice Hall, Inc. All rights reserved. 38

 2003 Prentice Hall, Inc. All rights reserved. 39

 2003 Prentice Hall, Inc. All rights reserved. 40