12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.

Slides:



Advertisements
Similar presentations
JDBC - Java Database Connectivity The objectives of this chapter are: To describe the architecture of JDBC To outline the classes in the java.sql package.
Advertisements

Fundamentals, Design, and Implementation, 9/e Chapter 14 JDBC, Java Server Pages, and MySQL.
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.
1 JDBC Java Database Connectivity. 2 c.pdf
EmbeddedSQL: 1 Impedance Mismatch Problem Problem : How to connect SQL statements with conventional programming languages Different models of language.
Session-01. Hibernate Framework ? Why we use Hibernate ?
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
The Java Persistence API Edel Sherratt. Contents Revisit applications programming Using Java Persistence API.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
1 CSC 440 Database Management Systems JDBC This presentation uses slides and lecture notes available from
CSCI 6962: Server-side Design and Programming
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
JDBC Java Database Connectivity. What is an RDBMS? Relational database management system. There are other kinds of DBMS. Access is a GUI on a JET RBDMS.
Think Possibility Integrating Web Applications With Databases.
Overview of JDBC and Pro*C 1 Overview of JDBC,Pro*C and Oracle connectivity on Omega CSE 5330 – Database Systems.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
JDBC. JDBC Drivers JDBC is an alternative to ODBC and ADO that provides database access to programs written in Java.
JDBC and Hibernate Joshua Scotton. Connecting to Relational DBs.
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
Overview of JDBC and Pro*C 1 CSE 5330 – Database Systems.
Connecting to Oracle using Java November 4, 2009 David Goldschmidt, Ph.D. David Goldschmidt, Ph.D.
JDBC Java and Databases, including Postgress. JDBC l Developed by Industry leaders l Three main goals: –JDBC should be an SQL-level API –JDBC should capitalize.
 What software components are required?  How do I install the Oracle JDBC driver?  How do I connect to the database?  What form is the data in and.
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
JDBC  The JDBC (Java Database Connectivity) API helps a Java program to access a database in a standard way  JDBC is a specification that tells the.
1 JDBC Aum Amriteshwaryai Namah. 2 2 JDBC – Java DataBase Connectivity.
Chapter 8 Databases.
JDBC Establish a connection with a database or access any tabular data source Send SQL statements Process the results Two major sets of interfaces: JDBC.
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.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
JPA / HIBERNATE CSCI 6370 Nilayan Bhattacharya Sanket Sable.
JDBC Database Programming in Java Prepared by., Mrs.S.Amudha AP/SWE.
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.
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.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC Session 14.
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
JSP/Database Connectivity Instructor: Dr. M. Anwar Hossain.
Hibernate Java Persistence API. What is Persistence Persistence: The continued or prolonged existence of something. Most Applications Achieve Persistence.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
CS3220 Web and Internet Programming Database Access with JDBC
JDBC 15-Apr-18.
JDBC Database Management Database connectivity
CS320 Web and Internet Programming Database Access with JDBC
A very brief introduction
Advanced Web Automation Using Selenium
JDBC 21-Aug-18.
HW#4 Making Simple BBS Using JDBC
Client Access, Queries, Stored Procedures, JDBC
Introduction to Server-Side Web Development using JSP and Databases
JDBC 15-Nov-18.
Bolat Azamat, Kim Dongmin
JDBC Example.
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Presentation transcript:

12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming

12-CRS-0106 REVISED 8 FEB 2013 An API that lets you access virtually any tabular data source from the Java programming language an interface which allows Java code to execute SQL statements inside relational databases –the databases must follow the ANSI SQL-2 standard Java Database Connectivity

12-CRS-0106 REVISED 8 FEB 2013 General Architecture

12-CRS-0106 REVISED 8 FEB 2013 Establish a connection Begin transaction Create a statement object Associate SQL with the statement object Provide values for statement parameters Execute the statement object Process the results End transaction Release resources Database Programming Steps

12-CRS-0106 REVISED 8 FEB 2013 Load the driver: –The driver class libraries need to be in the CLASSPATH for the Java compiler and for the Java virtual machine. –The most reliable way to load the driver into the program is:  Class.forName(string).newInstance(); Using JDBC

12-CRS-0106 REVISED 8 FEB 2013 Establish a connection to the database: –A connection URL string includes the literal jdbc:, followed by the name of the driver and a URL to the database  String url =  –Create a Connection object:  Connection con = DriverManager.getConnection(url, dbUser, dbPassword Using JDBC

12-CRS-0106 REVISED 8 FEB 2013 Begin the transaction –con.setTransactionIsolation(connection.TRANSACTION_SE RIALIZABLE ); –con.setAutoCommit( false ); Create a statement object –Statement stmt = conn.createStatement(); Associate SQL with the statement object –String queryString = "create table students " + "(name varchar(30), id int, phone char(9))"; Using JDBC

12-CRS-0106 REVISED 8 FEB 2013 Process the statement: –Example statements:  ResultSet rs = stmt.executeQuery(querystring);  int result = stmt.executeUpdate(updatestring);  ResultSetMetaData rsMeta = rs.getMetaData(); –Compiled queries can be processed via a PreparedStatement object –Stored procedures can be processed via a CallableStatement object Using JDBC

12-CRS-0106 REVISED 8 FEB 2013 End transaction –con.commit(); –con.rollback(); Release resources –con.close(); Using JDBC

12-CRS-0106 REVISED 8 FEB 2013 Question?

12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming

12-CRS-0106 REVISED 8 FEB 2013 Traditional vs object-oriented application

12-CRS-0106 REVISED 8 FEB 2013 RDBMS vs OODBMS Relational databases store data in tables that are two dimensional. –The tables have rows and columns. Relational database tables are "normalized" –data is not repeated more often than necessary. All table columns depend on a primary key (a unique value in the column) to identify the column. –Once the specific column is identified, data from one or more rows associated with that column may be obtained or changed.

12-CRS-0106 REVISED 8 FEB 2013 Hibernate ORM an object-relational mapping framework for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database. Hibernate solves object-relational impedance mismatch problems by replacing direct persistence-related database accesses with high- level object handling functions.

12-CRS-0106 REVISED 8 FEB 2013 Simple Tutorial Hibernate ORM In this example we use : –NetBeans IDE –Java 1.8 –Hibernate 4.3 –MySQL

12-CRS-0106 REVISED 8 FEB 2013 Class Model

12-CRS-0106 REVISED 8 FEB Create Database 1. Open services tab 2. Right-click at MySQL Server – Create Database 3. Name the database 4. Click ok

12-CRS-0106 REVISED 8 FEB Connect to the Database 1. Right-click at database – click Connect 2. Look at the connection created

12-CRS-0106 REVISED 8 FEB Create Hibernate Configuration 1. File -> New File 2. Select categories : Hibernate 3. Select Hibernate Configuration Wizard 4. Next 2 3

12-CRS-0106 REVISED 8 FEB Create Hibernate Configuration 5. Don’t change the name and location – Click Next 6. Select the database connection 7. Finish 5 6

12-CRS-0106 REVISED 8 FEB Create Hibernate Mapping 1. File -> New File 2. Select categories : Hibernate 3. Select Hibernate Mapping Wizard 4. Next 2 3

12-CRS-0106 REVISED 8 FEB Create Hibernate Mapping 5. Rename the name – student.hbm 6. next 5 6

12-CRS-0106 REVISED 8 FEB Create Hibernate Mapping 7. Select Student class in “Class to Map” column – Click “…” to browse 8. Finish 9. Do the same for class Teacher and Classroom 7 8

12-CRS-0106 REVISED 8 FEB Modify the mapping.xml Map object Student to table tbStudent Map object Teacher to table tbTeacher Map object Classroom to table tbClassroom –Map attribute teacher as a foreign key many-to-one to table tbteacher –Map attribute list student as foreign key one-to-many to table tbstudent

12-CRS-0106 REVISED 8 FEB a. student.hbm.xml

12-CRS-0106 REVISED 8 FEB b. teacher.hbm.xml

12-CRS-0106 REVISED 8 FEB c. classroom.hbm.xml

12-CRS-0106 REVISED 8 FEB Create Hibernate Util class 1. File -> New File 2. Select categories : Hibernate 3. Select HibernateUtil.java 4. Next 2 3

12-CRS-0106 REVISED 8 FEB Modify the HibernateUtil.java

12-CRS-0106 REVISED 8 FEB Modify the hibernate.cfg.xml Make sure the mapping xml is properly listed As you can see in source mode

12-CRS-0106 REVISED 8 FEB Modify the hibernate.cfg.xml Add connection information to your database –Add your username and password for database You might also add additional information

12-CRS-0106 REVISED 8 FEB Application Class

12-CRS-0106 REVISED 8 FEB Application Class – openConnection() closeConnection()

12-CRS-0106 REVISED 8 FEB Application Class – saveObject( o : Object )

12-CRS-0106 REVISED 8 FEB Application Class – loadAll()

12-CRS-0106 REVISED 8 FEB Application Class – updateObject( o : Object )

12-CRS-0106 REVISED 8 FEB Application Class – deleteObject( o : Object )

12-CRS-0106 REVISED 8 FEB Application Class – getClassroom() getStudent() getTeacher()

12-CRS-0106 REVISED 8 FEB 2013 Good to read en-US/html/

12-CRS-0106 REVISED 8 FEB 2013 THANK YOU Credits M usic : Yonezawa Madoka - Oui! Ai Kotoba (Instrumental)