Reflection API, JDBC, Hibernate, RMI

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

Basic JDBC Celsina Bignoli What is JDBC Industry standard for database- connectivity between the Java language and a wide range of.
Distributed Application Development B. Ramamurthy.
1 JDBC Java Database Connectivity. 2 c.pdf
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
Integration case study Week 8 – Lecture 1. Enrolment request (Workstation) Application server Database server Database New University Student Record System.
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
EmbeddedSQL: 1 Impedance Mismatch Problem Problem : How to connect SQL statements with conventional programming languages Different models of language.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
1 CSC 440 Database Management Systems JDBC This presentation uses slides and lecture notes available from
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
Database Management Systems 1 Oracle Programming.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Database Programming in Java Corresponds with Chapter 32, 33.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
Java + XML. Java 2 Enterprise Edition Server Side java Servlets JSP JavaBeans Web Services Database jdbc.
Introduction to JDBC Michelle Lee, Ye Wu & Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
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 8 Databases.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
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.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
UNIT III - JDBC JDBC Overview – JDBC implementation – Connection class – Statements - Catching Database Results, handling database Queries. Networking–
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
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.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC Session 14.
JDBC Java DataBase Connectivity. Loading the driver import java.sql.*... Class.forName("org.postgresql.Driver")‏
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Introduction – ORM, Helloworld Application
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
6-1 JAVA DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Review IS Overview: Data  Inside the application Collections  Outside the application Database XML  Getting/displaying Swing  Communicating.
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.
Remote Method Invocation Internet Computing Workshop Lecture 17.
January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,
Lec - 14.
JDBC – Java Database Connectivity
Distributed Computing
A very brief introduction
Remote Method Invocation
Advanced Web Automation Using Selenium
Client Access, Queries, Stored Procedures, JDBC
Objectives In this lesson, you will learn about:
Interacting with Database
Hibernate Bayu Priyambadha, S.Kom.
JDBC – ODBC DRIVERS.
Creating a Distributed System with RMI
Java Database Connectivity
Creating a Distributed System with RMI
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Creating a Distributed System with RMI
Java Remote Method Invocation
Creating a Distributed System with RMI
Presentation transcript:

Reflection API, JDBC, Hibernate, RMI James Atlas July 22, 2008

Reflection API Examine or modify the runtime behavior Allows programatic access to Java internals Fields Methods Constructors Classes Access by name and argument type java.lang.reflect.* July 22, 2008 James Atlas - CISC370

Reflection API java.lang.Class java.lang.reflect.Constructor annotations modifiers constructors, methods, fields java.lang.reflect.Constructor newInstance(object..) July 22, 2008 James Atlas - CISC370

Reflection API java.lang.reflect.Field java.lang.reflect.Method annotations declaring class modifiers get(object) java.lang.reflect.Method invoke(object..) July 22, 2008 James Atlas - CISC370

JDBC: Java Database Connectivity Database-independent connectivity Connect to database Get information from database Update data in database Classes in java.sql.* package In Java, two steps Establish a connection with a database Execute queries, statements against database July 22, 2008 James Atlas - CISC370

JDBC: Creating a Connection Load the DB driver Classes/library used to connect to the database Specific to the type of database Load the class by name Class.forName("sun.jdbc.odbc.JdbcOdbcDriver”); Create the connection (see API for all ways) String url = ”jdbc:mysql://localhost:3306/masplasDB"; Connection con = DriverManager.getConnection(url, loginname, password); Need to close connection when done con.close() Type of DB Location of DB, port DB name July 22, 2008 James Atlas - CISC370

JDBC: Executing Queries: Statements Statement stmt = con.createStatement(); executeQuery(String query) Returns a ResultSet Iterate through ResultSet, row-by-row, getting results from each column stmt.executeQuery(“SELECT * FROM COFFEES”); executeUpdate(String query) to update table Returns an integer representing the number of affected rows or 0 for SQL statements that don’t execute anything July 22, 2008 James Atlas - CISC370

JDBC: Prepared Statements prepareStatement(String template) Compile SQL statement “templates” Reuse statement, passing in parameters Java handles formatting of Strings, etc. as parameters updateSales = con.prepareStatement( "UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?"); Set parameters updateSales.setInt(1, 100); updateSales.setString(2, “French Roast”); Parameters July 22, 2008 James Atlas - CISC370

JDBC API Documentation: java.sql.* Limitations Statements, Connections, ResultSets, etc. are all Interfaces Driver/Library implements interfaces for its database Limitations Java doesn’t compile the SQL statements Exact syntax depends on DB Compile, run, verify queries outside of Java for your database Then copy and use in Java code July 22, 2008 James Atlas - CISC370

Hibernate “Hibernate's goal is to relieve the developer from 95 percent of common data persistence related programming tasks, compared to manual coding with SQL and the JDBC API” Object to relational mapping Integrated caching/pooling Transparent persistence Object-oriented query language (HQL) Very common in high-end business Java applications July 22, 2008 James Atlas - CISC370

Hibernate example: Event persistence We want to persist an Event object in a relational database Event has properties: ID (Long) Title (String) Date (Date) JavaBean pattern getProperty setProperty empty constructor July 22, 2008 James Atlas - CISC370

Hibernate example: mapping XML <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="events.Event" table="EVENTS"> <id name="id" column="EVENT_ID"> <generator class="native"/> </id> <property name="date" type="timestamp" column="EVENT_DATE"/> <property name="title"/> </class> </hibernate-mapping> July 22, 2008 James Atlas - CISC370

Hibernate example: insert/select Session session = getSessionFactory().getCurrentSession(); Event theEvent = new Event(); theEvent.setTitle(title); theEvent.setDate(theDate); session.save(theEvent); select List events = session.createQuery("from Event").list(); for (int i = 0; i < events.size(); i++) { Event theEvent = (Event) events.get(i); System.out.println("Event: " + theEvent.getTitle() + " Time: " + theEvent.getDate()); } July 22, 2008 James Atlas - CISC370

Distributed Programming Two primary ways to communicate Message passing (servlets, web services) Remote method calls an object on one computer calls methods of an object on a different computer method call looks like a method call on a local object Remote Method Invocation (RMI) July 22, 2008 James Atlas - CISC370

Java RMI: Remote Method Invocation Lookup an object by name registry Naming service Client Object location Bind object to a name RMI Server Invoke methods on object “stubs” Appears as calling method on local objects Objects that implement java.rmi.Remote July 22, 2008 James Atlas - CISC370

Why Java RMI? Write distributed programs RMI automates a lot of process Does not require network programming, sockets Load class definitions for objects that are passed around July 22, 2008 James Atlas - CISC370

Example: Compute Engine Compute Engine runs on a high performance machine Clients submit compute intensive tasks and receive results July 22, 2008 James Atlas - CISC370

Example: Compute Engine Server java.rmi.Remote Task Compute +executeTask(Task<T>):T Pi Pi BigDecimal ComputePi ComputeEngine July 22, 2008 James Atlas - CISC370