Databases and MySQL. COMP 342: Programming Methods. 16 September Databases and MySQL

Similar documents
Discuss setting up JDBC connectivity. Demonstrate a JDBC program Discuss and demonstrate methods associated with JDBC connectivity

Java application using JDBC to connect to a database.

JDBC Drivers Type. JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server.

Working with Databases and Java

Kyle Brown Knowledge Systems Corporation by Kyle Brown and Knowledge Systems Corporation

MANTHLY TEST SEPTEMBER 2017 QUESTION BANK CLASS: XII SUBJECT: INFORMATICS PRACTICES (065)

DataBase Lab JAVA-DATABASE CONNECTION. Eng. Haneen El-masry

Lab # 9. Java to Database Connection

Questions and Answers. A. A DataSource is the basic service for managing a set of JDBC drivers.

e-pg Pathshala Subject: Computer Science Paper: Web Technology Module: JDBC INTRODUCTION Module No: CS/WT/26 Quadrant 2 e-text

Enterprise Java Unit 1- Chapter 6 Prof. Sujata Rizal

13 Creation and Manipulation of Tables and Databases

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

JDBC [Java DataBase Connectivity]

Database Programming Overview. COSC 304 Introduction to Database Systems. Database Programming. JDBC Interfaces. JDBC Overview

CSE 308. Database Issues. Goals. Separate the application code from the database

Cyrus Shahabi Computer Science Department University of Southern California C. Shahabi

Application Programming for Relational Databases

Top 50 JDBC Interview Questions and Answers

JDBC MOCK TEST JDBC MOCK TEST IV

SQL in a Server Environment

Student Number: Please fill out the identification section above as well as the one on the back page, and read the instructions below. Good Luck!

JDBC. Sun Microsystems has included JDBC API as a part of J2SDK to develop Java applications that can communicate with databases.

This lecture. Databases - JDBC I. Application Programs. Database Access End Users

CSCI/CMPE Object-Oriented Programming in Java JDBC. Dongchul Kim. Department of Computer Science University of Texas Rio Grande Valley

JAVA AND DATABASES. Summer 2018

Introduction to SQL & Database Application Development Using Java

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

UNIT III - JDBC Two Marks

Intoduction to JDBC (Java Database Connectivity-- Connecting to DBMS)

JDBC - INTERVIEW QUESTIONS

JDBC Architecture. JDBC API: This provides the application-to- JDBC Manager connection.

CS221 Lecture: Java Database Connectivity (JDBC)

Wentworth Institute of Technology COMP570 Database Applications Fall 2014 Derbinsky. SQL Programming. Lecture 8. SQL Programming

Advanced SQL GROUP BY Clause and Aggregate Functions Pg 1

JDBC BASIC 19/05/2012. Objectives. Java Database Connectivity. Definitions of JDBC. Part 1. JDBC basic Working with JDBC Adv anced JDBC programming

Accessing a database from Java. Using JDBC

JDBC Programming: Intro

Unit 3 - Java Data Base Connectivity

SNS COLLEGE OF ENGINEERING, Coimbatore

Chapter 13 Introduction to SQL Programming Techniques

UNIT-3 Java Database Client/Server

An introduction for the novice. David Lawrence, JLab. 5/8/07 MySQL David Lawrence 1/36

Chapter 16: Databases

Chapter 3 DB-Gateways

O ne of the most important features of JavaServer

DB I. 1 Dr. Ahmed ElShafee, Java course

Part I: Stored Procedures. Introduction to SQL Programming Techniques. CSC 375, Fall 2017

SQL DML and DB Applications, JDBC

Using Java - for PL/SQL and Database Developers Student Guide

More Database Programming. CS157A Chris Pollett Nov. 2, 2005.

Intro to Structured Query Language Part I

Retrieving Data Using the SQL SELECT Statement. Copyright 2009, Oracle. All rights reserved.

Project Documentation

IBM DB2 9 Family Fundamentals. Download Full Version :

INTERMEDIATE SQL GOING BEYOND THE SELECT. Created by Brian Duffey

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Running SQL in Java and PHP

King Fahd University of Petroleum and Minerals

Java Database Connectivity (JDBC) 25.1 What is JDBC?

Programming in Java

PERSİSTENCE OBJECT RELATİON MAPPİNG

Acknowledgments About the Authors

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

Outline. Lecture 10: Database Connectivity -JDBC. Java Persistence. Persistence via Database

Limit Rows Selected. Copyright 2008, Oracle. All rights reserved.

Extracts from Intro to Db - Jdbc - JPA SpringData

HPCC JDBC Driver. Boca Raton Documentation Team

Database Management Systems,

Databases and SQL Lab EECS 448

Database Programming with SQL

Assignment 7: Integrity Constraints

Introduction to JDBC. JDBC: Java Database Connectivity. Why Access a Database with Java? Compilation. Six Steps. Packages to Import

Database Access with JDBC. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Chapter 9 SQL in a server environment

The Design of JDBC The Structured Query Language Basic JDBC Programming Concepts Query Execution Scrollable and Updatable Result Sets

INTRODUCTION TO JDBC - Revised Spring

Running SQL in Java and PHP

Database Languages. A DBMS provides two types of languages: Language for accessing & manipulating the data. Language for defining a database schema

Chapter 4. Windows Database Using Related Tables The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

CMPUT 391 Database Management Systems. JDBC in Review. - Lab 2 -

Advance Database Systems. Joining Concepts in Advanced SQL Lecture# 4

Lecture 2. Introduction to JDBC

JDBC Java Database Connectivity is a Java feature that lets you connect

Java and the Java DataBase Connectivity (JDBC) API. Todd Kaufman April 25, 2002

A subquery is a nested query inserted inside a large query Generally occurs with select, from, where Also known as inner query or inner select,

Pieter van den Hombergh. March 25, 2018

Database Design and Programming

COMP 430 Intro. to Database Systems. SQL from application code

INTRODUCTION TO JDBC - Revised spring

Enterprise Systems. Lecture 02: JDBC. Behzad BORDBAR

Embedded SQL. csc343, Introduction to Databases Diane Horton with examples from Ullman and Widom Fall 2014

Unit 2 JDBC Programming

Managing Your Database Using Oracle SQL Developer

Chapter 3 DB-Gateways

Introduction to Databases [p.3]

Allenhouse Institute of Technology (UPTU Code : 505) OOT Notes By Hammad Lari for B.Tech CSE V th Sem

SQL in a Server Environment (ii)

CSE 135. Applications View of a Relational Database Management System (RDBMS) SQL. Persistent data structure. High-level API for access &modification

Persistency Patterns. Repository and DAO

Transcription:

Databases and MySQL COMP 342: Programming Methods 16 September 2008 Databases and MySQL

Database basics What is a database? A database consists of some number of tables. Each table consists of field names and entries. A field name consists of a textual name and data type. An entry consists of values for each field. Think of the fields as column headers, entries as rows in the table. Databases and MySQL 1 / 11

A sample Human Resources database Employees table: lastname:string firstname:string positionid:integer hiredate:date Smith Joe 37 12 Nov. 1987 Doe Jane 1 4 Dec. 1098 Danner Norman 37 1984 Positions table: id:integer title:string minsal:currency maxsal:currency 1 President 23, 000 1, 000, 000, 000 2 Vice-president 20, 000 1, 500, 000... 37 Peon 1 10 Databases and MySQL 2 / 11

Database basics Relational databases Relations databases are characterized by the relationships between entries in different tables. Example: can require that each ID be distinct in Positions. Example: can require that positionid field of each entry in Employees matches the id field of one of the entries in Positions. This is called a foreign-key constraint. Look at some tables in the Petstore database. Databases and MySQL 3 / 11

Structured Query Language Interact with many databases by executing Structured Query Language (SQL) commands. Commands for 1. Creating tables; 2. Modifying tables; 3. Extracting data from the tables. We will mostly be concerned with data extraction. Databases and MySQL 4 / 11

Structured Query Language Basic SQL query select <field-spec> from <table-spec> [where <cond>] <field-spec> is a field specification; e.g.: * for all columns; lastname, firstname, salary for specific columns. <table-spec> is the name of a table in the database. <cond> is a boolean condition used to limit which rows are returned. The query returns a new table: 1. Get rows from <table-spec> that satsify <cond>. 2. Delete fields not in <field-spec>. Databases and MySQL 5 / 11

Structured Query Language A simple query select firstname, lastname from Employees where positionid = 37 Returns firstname:string Joe Norman lastname:string Smith Danner Some examples from the Petstore database. Databases and MySQL 6 / 11

Structured Query Language A JOIN query If multiple tables are specified in the from clause, the tables are joined: there is one result row for each combination of rows from each of the tables. select firstname, lastname from Employees, Positions where employees.positionid = Positions.id and Positions.minSal > 15000 Returns firstname:string Jane lastname:string Doe Databases and MySQL 7 / 11

The JDBC API The Java Database Connectivity Framework Provides interfaces for managing and interacting with databases. For simple SQL queries << interface >> Connection +createstatement():statement +preparecall(statement:string):callablestatement Iterator over table produced by a query; starts just before first row. getxxx() methods get column entry according to column type. << interface >> Statement << interface >> ResultSet +executequery (sqlquery:string):resultset +getresultset():resultset +getmoreresults():boolean +getint(col:string):int +getstring(col:string):string +next():boolean +getmetadata():resultsetmetadata For complex SQL queries with parameters. << interface >> PreparedStatement +execute():boolean << interface >> ResultSetMetaData For stored procedures. << interface >> CallableStatement Meta-data about the table for which this ResultSet is an iterator. Databases and MySQL 8 / 11

The JDBC API The Connection interface Represents a connection to the database. Obtained from the DriverManager, which in turn depends on a database system-dependent class. Steps: 1. Load database system-dependent driver into JVM with Class.forName(). 2. Get Connection object from DriverManager with getconnection, which requires information such as hostname, port, connection protocol, etc. Databases and MySQL 9 / 11

The JDBC API The Statement interface Represents a statement (SQL query, stored procedure, etc.) to be executed by database. Obtained from Connection object with createstatement. Typically for simple SQL statements; for us, typically for simple SQL queries that return a single table. ResultSet executequery(string sqlquery): executes the stock SQL query given by argument, returns the results via a ResultSet object. Databases and MySQL 10 / 11

The JDBC API The ResultSet interface An iterator over the table of data produced by an SQL query. Starts just before first row of table. Advance to next row with next(). Get column values for current row with getxxx methods. Databases and MySQL 11 / 11