Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.

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

 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
CSE470 Software Engineering Fall Database Access through Java.
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
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.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
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.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
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.
 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.
 2003 Prentice Hall, Inc. All rights reserved. 1 Java Database Connectivity with JDBC TM.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
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.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
Chapter 25 Databases. Chapter Scope Database concepts Tables and queries SQL statements Managing data in a database Java Foundations, 3rd Edition, Lewis/DePasquale/Chase25.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
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.
SQL Unit – 2 Base Knowledge Presented By Mr. R.Aravindhan.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
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.
 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.
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
Basics of JDBC Session 14.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
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.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
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.
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Database Programming in Java
 2012 Pearson Education, Inc. All rights reserved.
Introduction to Structured Query Language(SQL)
Accessing Databases with JDBC
JDBC.
Structured Query Language (SQL) William Klingelsmith
Chapter 8 Working with Databases and MySQL
Chapter 22 - SQL, MySQL, DBI and ADO
Introduction To Structured Query Language (SQL)
Java Database Connectivity
Introduction To Structured Query Language (SQL)
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL (Structured Query Language) 4.Methods in packages java.sql & javax.sql

Intro to JDBC Popular Relational Databases: Oracle Microsoft SQL Server Sybase Informix Microsoft Access mySQL CloudScape … and many, many more! RDBMS (p.1)

Intro to JDBC A Database consists of: Tables, which store… records, which contain fields of information. Relational Databases: store data in multiple tables that can be related (or linked) to one another via key fields. RDBMS (p.2)

Intro to JDBC An example: let’s look at the Microsoft Access database we just used. RDBMS (p.3) NumberNameDepartmentSalaryLocation 23603Jones New Jersey 24568Kerwin New Jersey 34589Larson Los Angeles 35761Myers Orlando 47132Neumann New Jersey 78321Stephens Orlando Row ColumnPrimary key

Intro to JDBC RDBMS (p.4) A Sample Relational Database:

Intro to JDBC RDBMS (p.5) In this example, a one-to-many relationship exists between the Contacts table and the Calls table. Contacts.ContactID is the primary key; Calls.ContactID is the foreign key. Primary and foreign keys need not have the same name, but must be of the same data type.

Intro to JDBC JDBC Drivers (p.1)

Intro to JDBC JDBC Drivers (p.2) Sun’s JDBC-ODBC Bridge – a type 1 driver Tips: - Always use System DSN, so DSN is available to all - ODBC Data Sources are only available on LAN/WAN (Not Internet accessible) - Use a Java/NativeAPI driver to access databases via internet - More info: JDBC-ODBC Bridge DriverJDBC-ODBC Bridge Driver

Intro to JDBC JDBC Drivers (p.3) More drivers available at: Lab: Find a type 2, 3 or 4 driver to use with Microsoft Access Your driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverXYZ, you would load the driver with the following line of code: Class.forName("jdbc.DriverXYZ"); Another driver lab: Set up distributed DB at \\B122-1

Intro to JDBC SQL (Structured Query Language) (p.1) SQL is an industry standard for querying relational databases. Although SQL, like everything else in the software industry, exists in several versions and flavors, basic syntax is consistent and reliable across all systems and software. Database languages, such as SQL, ordinarily include two sublanguages: Data Definition Language (DDL) Data Manipulation Language (DML)

Intro to JDBC SQL (p.2) Data Definition Language (DDL): Enables developer to create and modify database architecture (tables, records, fields). Query keywords: CREATE TABLE ALTER TABLE DROP TABLE

Intro to JDBC SQL (p.3) Data Manipulation Language (DML): Enables developer to add, edit and delete records and retrieve data. Query keywords: SELECT – retrieves data from table(s) INSERT – populates table with data UPDATE – changes existing data in table DELETE – removes data from table

Intro to JDBC SQL (p.4) SELECT statement clauses: SELECT – Select and retrieve records FROM – Tables from which to get fields WHERE – Criteria for filtering selections GROUP BY – How to group found records HAVING – Used with GROUP BY to specify criteria ORDER BY – Criteria for ordering found records

Intro to JDBC SQL (p.5) SELECT statement syntax: Basic SELECT Query : SELECT FieldName, … FROM TableName, … Examples: SELECT * FROM Authors SELECT AuthorID, LastName FROM Authors

Intro to JDBC SQL (p.6) SELECT statement syntax: SELECT Query with WHERE clause: SELECT FieldName, … FROM TableName, … WHERE criteria Examples: SELECT * FROM Authors WHERE YearBorn > 1960 SELECT * FROM Authors WHERE LastName = ‘Dietel’ (WHERE operators:, =, =,, LIKE ( [?, *] )

Intro to JDBC SQL (p.7) SELECT statement syntax: ORDER BY Clause: SELECT FieldName, … FROM TableName, … WHERE criteria ORDER BY FieldName, … ASC | DESC Example: SELECT * FROM Authors ORDER BY LastName, FirstName DESC

Intro to JDBC SQL (p.8) SELECT statement syntax: WHERE with LIKE clause: SELECT * FROM Authors WHERE lastName LIKE ‘D*’ [Or, use ‘D%’ other DBs] LIKE clause wildcard operators: ? * [Or, _ % other DBs]

Intro to JDBC SQL (p.9) SELECT statement syntax: WHERE with LIKE clause: SELECT authorID, firstName, lastName FROM Authors WHERE lastName LIKE ‘?i*’ [Or, use ‘_i%’ other DBs] LIKE clause wildcard operators: ? * [Or, _ % other DBs]

Intro to JDBC SQL (p.10) SELECT statement syntax: A More Complex Example Using an Implied Join: SELECT PublisherName, Title FROM Publishers, Titles WHERE (Titles.PublisherID = Publishers.PublisherID) ORDER BY PublisherName, Title ASC OR SELECT Publishers.PublisherName, Titles.Title FROM Publishers, Titles WHERE (Titles.PublisherID = Publishers.PublisherID) ORDER BY Publishers.PublisherName, Titles.Title ASC

Intro to JDBC SQL (p.11) INSERT statement syntax: Basic INSERT Query : INSERT INTO tableName ( columnName1,.., columnNameN ) VALUES ( value1, …, valueN ) Example: INSERT INTO authors ( firstName, lastName ) VALUES ( ‘Sue’, ‘Smith’ )

Intro to JDBC SQL (p.12) UPDATE statement syntax: Basic UPDATE Query : UPDATE tableName SET columnName1 = value1, …, columnNameN = valueN WHERE criteria Example: UPDATE authors SET lastName = ‘Jones’ WHERE lastName = ‘Smith’ AND firstName = ‘Sue’

Intro to JDBC SQL (p.13) DELETE statement syntax: Basic DELETE Query : DELETE FROM tableName WHERE criteria Example: DELETE FROM authors WHERE lastName = ‘Jones’ AND firstName = ‘Sue’

Intro to JDBC Package java.sql (p.1) Result Sets ResultSet (Recordset in ASP): JDBC returns query results in a ResultSet Object ResultSets are retrieved by executing queries: resultSet = statement.executeQuery( query );

Intro to JDBC Package java.sql (p.2) Traversing Result Sets A ResultSet can be traversed forward and backward (depending on cursor type) using: resultSet.first(); resultSet.next(); resultSet.previous(); resultSet.last(); … and more!

Intro to JDBC Package java.sql (p.3) Data types for Result Sets Data can be retrieved from a ResultSet by using various getXXX methods: resultSet.getString(FieldName); // returns data as type resultSet.getFloat(FieldName); resultSet.getDate(FieldName); resultSet.getInt(FieldName); resultSet.getMetaData(); // returns ResultSetMetaData obj. … and more!

Intro to JDBC Package java.sql (p.4) Result Set Cursors