1 Middleware (2) Nclab M.S. Jinwon Lee. 2 Contents CGI, Servlet, JSP → Client Session Management JDBC (Java Database Connectivity) Connection pooling.

Slides:



Advertisements
Similar presentations
Lecture plan Information retrieval (from week 11)
Advertisements

Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Distributed Application Development B. Ramamurthy.
Servlets and a little bit of Web Services Russell Beale.
SQL (Structured Query Language) X/OPEN Call Level Interface For SQL ODBC (Open DataBase Connectivity) API JDBC (Java DataBase Connectivity) API SQL (Structured.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
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.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
ODBC and JDBC What are they – libraries of function calls that support SQL statements Why do we need them –Provide a way for an application to communicate.
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
Database Programming in Java Corresponds with Chapter 32, 33.
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
Session tracking There are a number of problems that arise from the fact that HTTP is a "stateless" protocol. In particular, when you are doing on- line.
Session Tracking - 2 Lec 32. Last Lecture Review  Session Tracking – why?  Need to store state – typical solutions Cookies – already learned URL Rewriting.
Web Application Development * These slides have been adapted and modified from CoreServlets course material (Marty Hall) and LUMS cs391 (Umair Javed).
Java Servlets & Java Server Pages Lecture July 2013.
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.
Chapter 6 Server-side Programming: Java Servlets
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
Saving Client State Session Tracking: Maintain state about series of requests from same client over time Using Cookies: Clients hold small amount of their.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
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.
Saving State on the WWW. The Issue  Connections on the WWW are stateless  Every time a link is followed is like the first time to the server — it has.
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.
JDBC CHAPTER-2. JDBC - Java Database Connectivity. JDBC from Sun Microsystems provides API or Protocol to interact with different databases. With the.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
JDBC By 朱志興. Four driver types of JDBC (1) JDBC-ODBC bridge plus ODBC driver: Java Database Client JDBC- ODBC bridge ODBC driver Database Server A B C.
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.
225 City Avenue, Suite 106 Bala Cynwyd, PA , phone , fax Connecting to a Database.
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.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
©SoftMooreSlide 1 Session Tracking with Servlets.
Basics of JDBC.
Basics of JDBC Session 14.
JDBC (Java Database Connectivity)
CSC 2720 Building Web Applications Managing Users' States – Cookies, URL-Rewriting, Hidden Fields and Session Management APIs.
Servlets 4 Lec 30 Web Design and Development. Looking Back… Response Redirection  Sending a standard redirect  Sending a redirect to an error page Request.
JDBC Chapter 1 JDBC Introduction
Session Tracking Parts of this presentation was provided by SSE.
JDBC - Java Database Connectivity. JDBC provides Java applications with access to most database systems via SQL The architecture and API closely resemble.
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
8-Mar-16 More About Servlets Session Tracking. Persistent information A server site typically needs to maintain two kinds of persistent (remembered) information:
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
Net-centric Computing Servlets & JSP. Lecture Outline  Tracking Sessions  Cookies  Examples  JSP  Differences between JSP and Servlets  JSP Constructs.
R EMAINING TOPICS IN JDBC Sagun Dhakhwa. O VERVIEW Introduction to JDBC API Types of JDBC Drivers Introduction to ODBC.
Distributed Web Systems Cookies and Session Tracking Lecturer Department University.
DEPTT. OF COMP. SC & APPLICATIONS
Interacting with Database
Java Servlets By: Tejashri Udavant..
Chapter 26 Servlets.
Client / Session Identification Cookies
Mr. Harish Sharma Asst. Professor Dept. of CA & IT SGRRITS Dehradun
Interacting with Database
Introduction to Servlets
Java Database Connectivity
Java API for Database Connectivity
Presentation transcript:

1 Middleware (2) Nclab M.S. Jinwon Lee

2 Contents CGI, Servlet, JSP → Client Session Management JDBC (Java Database Connectivity) Connection pooling

3 Overview Client Browser Engine Supporting JSPs and Servlets Database JDBC Servlet JSP, Session Connection Pooling

4 Client Session Management

5 Stateless HTTP Protocol HTTP transaction is independent to each request. Problems at Data Tracking, User Identification. Ex) website login, shopping cart. Need to mange state information between transaction requests and Web Application → Session Tracking

6 Session Tracking Manage states information Client-side : Cookie Server-side: HttpSession (Servlet API)

7 Cookies A cookie is a piece of information that a site hands to your browser The browser hands the site the cookie on each subsequent request Unless the cookie is deleted, expired, modified..

8 Servlet/JSP support Cookies Javax.serlvet.http package support Cookie class Send to Client (HttpServletResponse class) Cookie myCookie = new Cookie(“key”, “value”) // Create cookie and Set attribute response.addCookie(myCookie); // Send Cookie to Client(Cookie is part of the HTTP response header.) Receive from Client(HttpServletRequest class) Cookie [] allCookie = request.getCookies(); // Receive allCookie from Client String value = myCookie[i].getValue(); // Find the specific one you are interested in

9 Cookies don’t always taste good Cookies can only contain small amounts of data (all cookie data are strings) Cookies might not be accepted by the browser Cookies can get stale → Use Object in Server-side (HttpSession)

10 HttpSession A session is a continuous connection from the same browser over a fixed period of time. Default is 30 minutes for Servlet Container To maintain session information, Use session with browser cookies or encodeURL Javax.servlet.http package support HttpSession interface

11 HttpSession How to obtain HttpSession object HttpSession session = request.getSession(true); // read session id from cookie or encodeURL,and // if there are valid session object, return object. // else create new session with cookie You can maintain a set of (key, value) paired information in the HttpSession object. To store session-specific information, use the putValue(key, value) & getValue(key).

12 encodeURL If the browser doesn’t accept cookies, session id is appended to each URL in the HTML response When the rewritten URL is accessed, the server extracts the appended session id String URL encodeURL(String URL); session id is append to URL and return URL [URL] [After encodeURL] xxxxxxx

13 Session Implemention Informations of HTTP transaction are managed by using HttpSession → Security, efficiency To track the HttpSession, it is the best way that user accept cookie

14 JDBC

15 JDBC Application 개발시 Database system 과의 연동이 필수적 → JDBC (Java Database Connectivity) JDBC API Java 로 작성된 Program 을 일반 Database 에 연결하기 위한 API 제공

16 JDBC Overview DB 와 User 사이에 Abstract Layer 제공. 한가지 API 만을 이용하여 서로 상이한 DB 사용 가능. 대부분의 DB Vendor 가 JDBC Spec. 에 따 라 JDBC Driver 를 구현하여 제공.

17 Java Application JDBC Driver Manager (java.sql.*) JDBC Driver JDBC API JDBC Driver API DB

18 JDBC Driver Type I : JDBC-ODBC bridge plus ODBC driver DataBase JAVA 어플리케이션 JDBC-ODBC Bridge 기존의 ODBC 드라이버 Native API( C/C++) DataBase protocol

19 Type II : Native-API partly-Java driver ( JDBC 의 호출을 각 DB Client API 로 변환하여 호출 )

20 Type III: JDBC-Net pure Java driver

21 Type IV: Native-protocol pure Java driver

22 장점 JDBC 호출을 DBMS 의 고유한 Protocol 로 직접 변환해 처리하기 때문에 처리 속도가 가장 빠르다. Internet/Intranet 에 가장 적합한 방식 단점 DB 고유의 Protocol 을 알고 있어야만 하므로 JDBC Driver Vendor 가 만들기에는 어렵고 주로 DBMS Vendor 에 의해 제공된다.

23 java.sql package JDBC 2.0 core API Major interface Making a connection with a data source DriverManager class Connection interface Sending SQL statements to a database Statement interface Retrieving and updating the results of a query ResultSet interface Throwing exceptions SQLException

24 Programming with JDBC API 1. DriverManager 에 해당 DBMS driver 등록 Class.forName(String className ); “com.jk.jdbc.Driver” 2. 해당 Driver 로부터 Connection 객체 획득 String 1433"; String user=“scott”; String passwd=“tiger”; Connection conn=DriverManager.getConnection( jdbcURL, user, passwd);

25 3. Connection 객체로부터 Statement 객체 획득 Statement stmt=conn.createStatement(); 4. Statement method 를 이용하여 SQL 실행 ResultSet rset=stmt.executeQuery(“SELECT id, name FROM emp”); 5. 결과를 ResultSet 으로 받아서 처리 while(rset.next()) { System.out.println(“ 사번 :” + rset.getInt(“id”)); System.out.println(“ 이름 :” + rset.getString(“name”)); } 6. 종료 rset.close(); stmt.close(); conn.close();

26 Problems Accessing the database can be slow Lots of years and tears are spent optimizing database access An obvious optimization is to reuse the JDBC connections

27 References Books Professional Java server programming Website (servlet/jsp lecture 7 ~ 9)