Chapter 15 Using a Database.

Slides:



Advertisements
Similar presentations
Chapter 10 ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a programming interface to access data in a database.
Advertisements

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.
Distributed Application Development B. Ramamurthy.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
Database Application Programming (C#) Chris North CS 4604: DB.
CIS 270—App Dev II Big Java Chapter 22 Relational Databases.
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
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.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 8 Object Oriented Programming in Java Advanced Topics Java Database.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Java Utility Classes CS 21b. Some Java Utility Classes Vector Hashtable StringTokenizer * import java.util.*;
CIS 451: Using ASP.NET Objects with SQL Dr. Ralph D. Westfall February, 2009.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
MySQL Connection using ADO.Net Connecting to MySQL from.NET Languages.
Connecting to Oracle using Java November 4, 2009 David Goldschmidt, Ph.D. David Goldschmidt, Ph.D.
Introduction to JDBC Michelle Lee, Ye Wu & Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
 It is the primary data access model for.Net applications  Next version of ADO  Can be divided into two parts ◦ Providers ◦ DataSets  Resides in System.Data.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
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.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
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.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Java Database Connectivity. Java and the database Database is used to store data. It is also known as persistent storage as the data is stored and can.
 It is the primary data access model for.Net applications  Next version of ADO  Can be divided into two parts ◦ Providers ◦ DataSets  Resides in System.Data.
1 11/10/05CS360 Windows Programming ADO.NET. 2 11/10/05CS360 Windows Programming ADO.NET  Behind every great application is a database manager o Amazon.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
JDBC Database Programming in Java Prepared by., Mrs.S.Amudha AP/SWE.
Visual Programing SQL Overview Section 1.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
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.
Distributed Database Systems INF413. ADO.NET is a set of classes that comes with the Microsoft.NET framework to facilitate data access from managed languages.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
HNDIT Rapid Application Development
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC Session 14.
Module 4 Introduction ADO.NET.
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.
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
Using Database: A very, very short introduction..
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
ADO .NET from. ADO .NET from “ADO .Net” Evolution/History of ADO.NET MICROSOFT .NET “ADO .Net” Evolution/History of ADO.NET History: Most applications.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
Web Systems & Technologies
CS320 Web and Internet Programming SQL and MySQL
ADO.NET Framework.
ISC440: Web Programming 2 Server-side Scripting PHP 3
ADO.Net and Stored Procedures
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
MySQL Connection using ADO.Net
Browser (Client Side) 瀏覽器 (客戶端)
Java Database Connectivity
CS3220 Web and Internet Programming SQL and MySQL
Chapter 4 Introduction to MySQL.
CS3220 Web and Internet Programming SQL and MySQL
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
JDBC II IS
Presentation transcript:

Chapter 15 Using a Database

Database tables Relational database keep data in tables do not include redundant information Key identifies the data in a row Sales database example has five tables Customer, Salesperson, Item, Orders, and OrderItem

CustomerID CustomerName Address BalanceDue 1234 Fred Flynn 22 First St. 1667.00 5678 Darnell Davis 33 Second St. 130.95 4321 Marla Martinez 44 Third St. 8765 Carla Kahn 55 Fourth St. Figure 15.1 The Customer table

SalespersonID SalespersonName Address 12 Peter Patterson 66 Fifth St. 98 Donna Dubarian 77 Sixth St. Figure 15.2 The Salesperson table

ItemNumber Description Quantity 222222 radio 32 333333 television 14 444444 computer 9 Figure 15.3 The Item table

OrderNumber CustomerID SalespersonID OrderDate 1 1234 12 4/3/99 2 5678 3/22/99 3 8765 98 2/19/99 4 4/5/99 5 2/28/99 Figure 15.4 The Orders table

OrderNumber ItemNumber Quantity UnitPrice 1 222222 4 27.00 333333 2 210.50 444444 569.00 230.95 3 5 725.00 Figure 15.5 The OrderItem table

Type Standard SQL Description CHAR(N) Fixed size string of length N VARCHAR(N) Variable size string up to length N INTEGER 32-bit integer DATE Year, month, and day DECIMAL Used for dollars and cents Figure 15.6 SQL data types

CREATE TABLE tablename (fieldname1 TYPE1, fieldname2 TYPE2, ... , fieldnameN TYPEn) INSERT INTO tablename VALUES (field1value,field2value, ..., fieldNvalue) DELETE FROM tablename WHERE fieldname1 = value1 ... AND fieldnameN = valueN UPDATE tablename SET fieldnameToSet = newValue WHERE fieldname1ToCheck = value1ToCheck SELECT fieldname1, ..., fieldnameN FROM table1, ..., tableM WHERE condition1 ... AND conditionN Figure 15.7 Some patterns for SQL statements

Client1 Database Server Client 2 Figure 15.8 Client-server database access

Client1 Application Server Database Server Client2 Figure 15.9 A three-tiered system architecture

Database Drivers JDBC statements are database independent A driver translates from JDBC to vendor’s database commands Database vendors provide JDBC drivers e.g Oracle, mySQL Microsoft Access has an ODBC driver Use JdbcOdbc bridge to convert from JDBC to ODBC driver Must register ODBC data source

Connecting to Microsoft Access String connect = "Provider=Microsoft.JET.OLEDB.4.0;“ +@"data source= c:\booksharp\gittleman\ch15\Sales.mdb"; OleDbConnection con = new OleDbConnection(connect); con.Open(); Console.WriteLine ("Made the connection to the Sales database"); con.Close();

Creating a database Do not need C#, can do it in Access OleDbCommand cmd = con.CreateCommand(); cmd.CommandText = “SQL here”; cmd.ExecuteNonQuery(); SQL CREATE to create a new table SQL INSERT to insert data

Retrieving Information cmd.CommandText = "SELECT CustomerName, Address " + "FROM Customer ORDER BY CustomerName"; reader = cmd.ExecuteReader(); while(reader.Read()) Console.WriteLine("{0}\t{1}", reader.GetString(0), reader.GetString(1)); reader.Close();

Java method SQL type GetInt32 INTEGER GetString VARCHAR GetDecimal DECIMAL GetDate DATE Figure 15.12 C# methods for SQL types

Customer ordering computers SELECT DISTINCT CustomerName FROM Customer, Item, Orders, OrderItem WHERE Customer.CustomerID = Orders.CustomerID AND Orders.OrderNumber = OrderItem.OrderNumber AND OrderItem.ItemNumber = Item.ItemNumber AND Description = 'computer'

Database Info The GetOleDbSchemaTable method returns information about the data set. This method has two parameters a Guid and an Object[] The Guid is a globally unique 128-bit identifier that is unique across all computers and networks. We use OleDbSchemaGuid values. The two we illustrate are Tables and Columns. Using Tables will return a table that describes each table in the data set. Using Columns will return a table that describes each column.

DataSet Create a DataSet and process the data offline Use an OleDbDataAdapter to fill the DataSet Get the DataTable objects

Stored Procedures Compile once, run many times with different parameters cmd.CommandText = "SELECT Quantity FROM Item " + "WHERE Description = ?"; OleDbParameter param = new OleDbParameter(); cmd.Parameters.Add(param); param.Value = "radio"; OleDbDataReader reader = cmd.ExecuteReader(); while(reader.Read()) Console.WriteLine("{0}", reader.GetInt32(0)); reader.Close();

Transactions All parts must succeed for transaction to succeed OleDbTransaction trans = con.BeginTransaction(); cmd.Transaction = trans; trans.Commit(); // if transaction succeeds trans.Rollback(); // undoes changes from start // or last Commit