Advanced Java Session 5 New York University School of Continuing and Professional Studies.

Slides:



Advertisements
Similar presentations
Distributed Application Development B. Ramamurthy.
Advertisements

Java Database Connectivity JDBC ICW Lecture 12 Errol Thompson.
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.
EmbeddedSQL: 1 Impedance Mismatch Problem Problem : How to connect SQL statements with conventional programming languages Different models of language.
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
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. –
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
Think Possibility Integrating Web Applications With Databases.
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
© 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 ASE. Java Database Connectivity (JDBC) l JDBC – provides an interface to Relational Data Sources l JDBC library provides the.
Database Programming in Java Corresponds with Chapter 32, 33.
Java Utility Classes CS 21b. Some Java Utility Classes Vector Hashtable StringTokenizer * import java.util.*;
JDBC. JDBC Drivers JDBC is an alternative to ODBC and ADO that provides database access to programs written in Java.
Dr R R DOCSIT, Dr BAMU. Basic Java : Introduction to JDBC 2 Objectives of This Session State what is Java Database Connectivity State different.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
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,
Connecting to Oracle using Java November 4, 2009 David Goldschmidt, Ph.D. David Goldschmidt, Ph.D.
Java + XML. Java 2 Enterprise Edition Server Side java Servlets JSP JavaBeans Web Services Database jdbc.
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.
JDBC – Java DataBase Connectivity. JDBC API Overview JDBC is Java API that allows the Java programmers to access database management system from Java.
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.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
JDBC Session 2 Tonight’s topics: 1.Prepared Statements 2.Transaction Processing 3.Callable Statements & Stored Procedures 4.Scrollable & Updatable Result.
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. Java and the database Database is used to store data. It is also known as persistent storage as the data is stored and can.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
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.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
Session 30 Basics of JDBC. Java Simplified / Session 30 / 2 of 33 Review A Swing menu consists of a menubar, menuitems and menus. Trees are used to depict.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
Li Tak Sing COMPS311F. Database programming JDBC (Java Database Connectivity) Java version of ODBC (Open Database Connectivity) ODBC provides a standard.
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.
JDBC and SQLJ CIS 612 Spring JDBC JDBC is an API that enables database access from Java programs JDBC for DB access provides ◦ Portability across.
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)
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
6-1 JAVA DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
CS422 Principles of Database Systems JDBC and Embedded SQL Chengyu Sun California State University, Los Angeles.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
JDBC Statements The JDBC Statement, CallableStatement, and PreparedStatement interfaces define the methods and properties that enables to send SQL or PL/SQL.
JDBC. Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most.
Lec - 14.
JDBC Database Management Database connectivity
Advanced Web Automation Using Selenium
HW#4 Making Simple BBS Using JDBC
Client Access, Queries, Stored Procedures, JDBC
JDBC – ODBC DRIVERS.
Java Database Connectivity
Bolat Azamat, Kim Dongmin
Java API for Database Connectivity
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Advanced Java Session 5 New York University School of Continuing and Professional Studies

2 Objectives Java Beans – Part 2 –ImageViewerBean Relational Database concepts –Schema, tables, fields, rows –Common SQL queries – SELECT, INSERT, UPDATE JDBC –design –Basic JDBC Programming Concepts –Populating database/Executing Queries Java Servlets –Overview and Basic Servlet structure

3 BeanBox Installing and launching Using BeanBox to create applications Creating JavaBean jar files –jar cvfm filename.Jar manifestfile classes

4 Adding Custom Bean Events Write a class Event that extends EventObject Write an interface Listener with a single notification method with any name that takes a single parameter Event and return type of “void” Supply the following two methods in the bean – –public void add Listener( Event e) –public void remove Listener( Event e)

5 TimerBean.java Example of adding custom bean events

6 Database Systems Relational Databases – organize data in the form of tables - Oracle Object Databases – organize data as objects - ObjectDB Hierarchical Databases – organize data in a hierarchical format - WWW Network Database – organize data as a network of nodes - dbVista

7 Relational Databases Tables Fields Key Index

8 Tables and Relations StudentIDName 1001Robert Estes CourseIDCourse 101Java2 1002Mitzy Capture 102Networking Students Courses RefIDStudentID 1001Robert Estes 1002Mitzy Capture CourseID Robert Estes Mitzy Capture StudentID StudentsXCourses Addr Addresses AdrId 1 2

9 Common Operations SELECT –Simple SELECT –Join of multiple tables UPDATE INSERT

10 JDBC Design Java Application JDBC Driver Manager Vendor- Supplied JDBC driver JDBC/ODBC Bridge ODBC db JDBC API JDBC Driver API

11 Driver Classification Type 1 –JDBC/ODBC bridge Type 2 –Partly in Java/Partly in native code Type 3 –Pure Java - through a middle tier Type 4 –Pure Java - directly to the Database Server

12 Typical Applications Java Applications Java Applets Web based Applications

13 Basic JDBC programming Make a connection with the database Prepare your query Supply values (bind variables) if necessary Execute your query Examine the results

14 Database URLs All start with “jdbc” Are provided with the drivers documentation. For example: jdbc:odbc:mydb

15 Loading the Driver class Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver” Or Use java -Djdbc.properties=filename

16 Making a Connection String url = “jdbc:odbc:mydb” String user=“java2” String pass=“java2” Connection con = DriverManager.getConnection(url, user, pass)

17 Creating JDBC Statements Statement stmt = con.createStatement()

18 Executing Statements that insert, update, or delete data String qry = “INSERT INTO Students (StudentID, Name) Values(1004,’anil’)” ResultSet rs = stmt.executeUpdate(qry);

19 Executing Statements that return rows String qry = “SELECT StudentID, Name FROM Students” ResultSet rs = stmt.executeQuery(qry);

20 Retrieving Values from ResultSet while ( rs.next() ) { int id = rs.getInt(“StudentID”); String name = rs.getString(“Name”); System.out.println(id+”\t”+name); }

21 Retrieving Values from ResultSet (using column ordinals) while ( rs.next() ) { int id = rs.getInt(1); String name = rs.getString(2); System.out.println(id+”\t”+name); }

22 Using “bind” variables String qry = “INSERT INTO STUDENTS (id, name) VALUES (?,?)” PreparedStatement pstmt = con.prepareStatement(qry);

23 Executing in a Loop for (i = 0; i < 10; i++) { pstmt.setInt(1, 1000+i); name = inputName(); pstmt.setString(2,name); int n = stmt.executeUpdate() }

24 Calling Stored Procedures String qry = “{call ProcessDailyChecks}” CallableStatement cstmt = con.prepareCall(qry); int n = cstmt.executeUpdate();

25 Using Metadata ResultSetMetaData rsmd = rs.getMetaData(); rsmd.getColumnCount() rsmd.getColumnName(int i) rsmd.getColumnType(int i) rsmd.getTableName(int i); rsmd.isAutoIncrement(int i);

26 Scrollable/Updateable ResultSets ResultSet rs = conn.createStatement(type, concurrency); Types: TYPE_FORWARD_ONLY, TYPE_SCROLL_SENSITIVE, TYPE_SCROLL_INSENSITIVE Concurrency:CONCUR_READ_ONLY CONCUR_UPDATABLE

27 Thank you