CIS 270—App Dev II Big Java Chapter 22 Relational Databases.

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

JDBC CS-328. JDBC Java API for accessing RDBMS Allows use of SQL for RDBMS programming Can be used for: –embedded SQL –execution of stored queries.
15-Jun-15 JDBC. JDBC is a Sun trademark It is often taken to stand for Java Database Connectivity Java is very standardized, but there are many versions.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Object Oriented Programming Java Java’s JDBC Allows access to any ANSI SQL-2 DBMS Does its work in terms of SQL The JDBC has classes that represent:
Creating a Blank Database 1. Open up Microsoft Access 2. Click on Blank document button 3. On the right panel, Specify the location for saving your database.
Concepts of Database Management Sixth Edition
CSE470 Software Engineering Fall Database Access through Java.
Concepts of Database Management Sixth Edition
Chapter Extension 6 Using Microsoft Access © 2008 Pearson Prentice Hall, Experiencing MIS, David Kroenke.
1 Client/Server Database Tutorial. SQL Server Connection through MS Access FACBUSAD1 SQL server MS Access MGD B106 Computer or your own PC Remote SQL.
Java MS Access database connectivity Follow these steps: 1)Go to the start->Control Panel->Administrative Tools- > data sources. 2)Click Add button and.
Chapter 2 Querying a Database
Introduction to JDBC (Java Database Connectivity).
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Chapter 3 Maintaining a Database
CSCI 6962: Server-side Design and Programming
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Helena Pomezná, ciz034 St. skupina: L392 FEI, VŠB-TUO Ak. rok. 2002/2003 Download:
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
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.
Jaeki Song JAVA Lecture 11 Java Database Connectivity.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
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.
Concepts of Database Management Seventh Edition
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
Georgia Institute of Technology Making Text for the Web part 5 Barb Ericson Georgia Institute of Technology March 2006.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
Microsoft Access 2010 Building and Using Queries.
WEEK 11 Database Design. TABLE INSTANCE CHARTS Create Tables.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
Chapter 8 Databases.
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.
© 2002 by Prentice Hall 1 Database Processing with Microsoft Access David M. Kroenke Database Concepts 1e Appendix A.
Databases,Tables and Forms Access Text by Grauer Chapters 1 & 2.
Database Processing with Microsoft Access Appendix DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
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.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
Presentation On How To Create Connection To A Database.
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.
EXAMPLE I An application showing JDBC access to Cloudscape.
CS 281 – Fall 2015 Lab 4 Parametric Query and Forms in MS Access.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
PHP Programming. Topics Database Handling (MySQL, MSSQL, ODBC)
CSI 3125, Preliminaries, page 1 JDBC. CSI 3125, Preliminaries, page 2 JDBC JDBC stands for Java Database Connectivity, which is a standard Java API (application.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
COMPREHENSIVE Access Tutorial 1 Creating a Database.
Chapter 5 Building Your Product Catalog database Objectives Create Database. Create Table. Connect to Database. Use ASP Script to add new products. Use.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
Database Processing with JSP ISYS 350. Database Applications Applications Database Server Queries/Updates Results.
Copyright © 2014 Pearson Canada Inc. Ext. 5b-1 Copyright © 2014 Pearson Canada Inc. Application Extension 5b Using Microsoft Access Part 2: Using Information.
Java Access to RDB Relational databases (RDBs) dominate today, due to:
Lec - 14.
JDBC 15-Apr-18.
, MS-Access, QBE, Access/Oracle
JDBC 21-Aug-18.
HW#4 Making Simple BBS Using JDBC
JDBC 15-Nov-18.
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

CIS 270—App Dev II Big Java Chapter 22 Relational Databases

Database Tables A relational database (DB) stores information in _________. Tables contain data in rows and __________. Columns represent data ________ such as SSN, Name, DateOfBirth, etc. Rows represent individual _________ such as students (which have SSN, Name, DateOfBirth, …). Data in relational databases are accessed using SQL (structured query ___________). Java can be used to send SQL commands to a DB. tables columns fields entities language

SQL Examples SQL command to create a product table: CREATE TABLE Product ( Product_Code CHAR(11), Description CHAR(40), Price DECIMAL(10, 2) ) Insert a _____ in a table: INSERT INTO Product VALUES (‘ ’, ‘Hair dryer’, 29.95) Remove a table from the DB: DROP TABLE Product row

Linking Tables A Customer class can have _________ fields that directly relate to columns in a relational table. – Customer table: customerId, name, address, city, state, zip However, an Invoice class may have a Customer object as an instance field (more complicated). This situation would require an Invoice table: – Invoice table: invoiceId, customerId, payment These two tables are linked by the customerId field, which is the primary _____ of Customer and a __________ key of Invoice. instance key foreign

Implementing Relationships Each invoice has exactly one customer, which is a _____ relationship (single-valued). But an invoice can have many line items (____ or multi-valued relationship): – private ArrayList items; This requires two more tables. – LineItem table: invoiceId, productId, quantity – Product table: productId, description, price Tables and relationships: Customer --- Invoice --- LineItem --- Product 1:1 1:n 1:1 1:n1:1

22.2 Queries I Use the SELECT command to _______ a database: – SELECT city, state FROM Customer – SELECT * FROM Customer WHERE State = ‘CA’ – SELECT * FROM Customer WHERE Name LIKE ‘_o%’ – SELECT * FROM Product WHERE Price < 100 AND Description <> ‘Toaster’ Above, the _ means ‘match ____ character’ and the % means ‘match any number of characters’ Calculations: – SELECT AVG(Price) FROM Product query one

22.2 Queries II Joins – SELECT LineItem.invoice_number FROM Product, LineItem WHERE Product.description = ‘Car vacuum’ AND Product.product_code = LineItem.product_code Updating and Deleting Data – DELETE FROM Customer WHERE State = ‘CA’ – UPDATE LineItem SET quantity = quantity + 1 WHERE invoice_number = ‘11731’

22.4 Create a DB and a DSN Create a database using Access and save to a folder Create a DSN (data ________ name) for the database – In Windows, click Start, Settings, Control Panel – Double-click Administrative Tools – Double-click Data Sources (ODBC) – Click User DSN tab – Click Add button – Select Microsoft Access Driver (*.mdb, *.accdb), click Finish – Enter a Data Source Name (your choice) – Click the Select button, navigate to the folder containing the database, select the database, click the database file – Click OK, OK, and OK source

22.4 Write the Java Program I Create a Connection object import java.sql.Connection; import java.sql.Statement; import java.sql.DriverManager; import java.sql.ResultSet; public class Test { public static void main( String[] args ) { try { Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ); String dataSourceName = "mdbTEST"; String dbURL = "jdbc:odbc:" + dataSourceName; Connection con = DriverManager.getConnection( dbURL, "","" );

22.4 Write the Java Program II Create an SQL Statement object and use it to execute various SQL commands Statement stmt = con.createStatement(); stmt.execute( “CREATE TABLE Table1 ( aColumnName integer )” ); stmt.execute( “INSERT INTO Table1 VALUES( 77 )” ); stmt.execute( “SELECT aColumnName FROM Table1” );

22.4 Write the Java Program III Create a ResultSet object and use it to display results ResultSet rs = stmt.getResultSet(); if ( rs != null ) while ( rs.next() ) { System.out.println( "Data from first column: " + rs.getString( 1 ) ); } stmt.execute( “DROP TABLE Table1" ); stmt.close(); con.close(); } // end try

22.4 Write the Java Program IV Finish up catch ( Exception err ) { System.out.println( "ERROR: " + err ); } // end catch } // end main } // end class Install the database, compile the Java program and run See code.com/vb/scripts/ShowCode.asp?txtCodeId=2 691&lngWId=2#SECTION_SQL for more discussionhttp:// code.com/vb/scripts/ShowCode.asp?txtCodeId=2 691&lngWId=2#SECTION_SQL