0% found this document useful (0 votes)
7 views

java-1-j2ee

The document outlines the course objectives and outcomes for a J2EE subject at Karpagam Academy of Higher Education, focusing on the architecture and platform for web-based enterprise applications. It includes detailed unit plans covering topics such as J2EE multi-tier architecture, database concepts, servlets, and Java Server Pages. Suggested readings and resources for further study are also provided.

Uploaded by

ravindra paliwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
7 views

java-1-j2ee

The document outlines the course objectives and outcomes for a J2EE subject at Karpagam Academy of Higher Education, focusing on the architecture and platform for web-based enterprise applications. It includes detailed unit plans covering topics such as J2EE multi-tier architecture, database concepts, servlets, and Java Server Pages. Suggested readings and resources for further study are also provided.

Uploaded by

ravindra paliwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 50
Bp) 2016- 2018 Batch slot, g ‘ KARPAGAM ACADEMY OF HIGHER EDUCATION N y (Deemed University Established Under Section 3 of UGC Act 1956) Pee Coimbatore — 641 021 siete (For the candidates admitted from 2016 onwards) DEPARTMENT OF COMPUTER SCIENCE, SUBJECT — : J2EE SEMESTER : III LTPC SUBJECT CODE: 16CSP301 CLASS _: IIM.Se.CS 4004 Course Objective: 1. To Understand J2EE as an architecture and platform for building and deploying web- based n-tier transactional component-based enterprise applications. 2. To Understand the EJB architecture and have a good grasp on when to use and how to use various EJB bean types and acquire relevant Java programming experience. 3. To learn the concepts of servlets and its purpose. 4. To become familiar with the web development environment. 5. To understand about java server pages and to develop dynamic web pages. Course Outcome: Afier the completion of this course, a successful student will be able to do the following: Thoroughly understand the JEEE architecture. Gain an in-depth understanding of database programming using JDBC. Develop Java Server Pages (JSPs). Implement simple JSPs that use Java code in declarations, expressions and scriptlets. Understand the design and development of web applications using Servlets and JSPs. yaeye UNIT-I J2EE Overview: Beginning of Java — Java Byte code - Advantages of Java -I2EE and J2SE. J2EE Multi Tier Architecture — Distributive Systems — The Tier - Multi Tier Architecture — Client Tier - Web Tier - Enterprise Java Beans Tier = Enterprise Information Systems Tier Implementation. Department of CS, CA & IT, KAHE 1 2016- 2018 Batch UNIT-AL J2EE Database Concepts: Data — Database — Database Schema. JDBC Objects: Driver Types — Packages — JDBC Process — Database Connection — Statement Objects - Result Set — Meta Data. T-H1 Java Servlets: Benefits — Anatomy — Reading Data from Client Reading HTTP Request Headers — Sending Data to client — Working with Cookies, UNIT-IV Enterprise Java Beans: Deployment Descriptors - Session Java Bean -Entity Java Bean Message Driven Bean TV ISP: What is Java Server Pages? - Evolution of Dynamic Content Technologies - JSP & Java 2 Enterprise edition. JSP Fundamentals: Writing your first JSP- Tag conversions- Running JSP. Programming JSP Scripts: Scripting Languages - JSP tags- JSP directives — Scripting elements — Flow of Control — comments. Java Remote Method Invocation. SUGGESTED READINGS TEXT BOOKS 1, Jim Keogh. (2010). The Complete Reference J2EE, Tata McGraw Hill: New Delhi, Ist Edition. 2. Duane, K. Fields., & Mark, A. Kolb. (2002). Web Development with Java Server Pages, Manning Publications, Pune, 2“ Edition. REFERENCES 1, David R. Heffelfinger (2011), Java EE 6 Development with NetBeans 7,Packt Publishers,1* Edition. 2. Joel Murach, Michael Urban, (2014), Murach's Java Servlets and JSP, (Murach: Training & Reference). 3rd Edition 3. Joseph, J. Bambara et al. (2007). J2EE Unleashed , New Delhi:Tech Media, 1* Edition. 4, Paul, J. Perrone., Venkata, S. R. Chaganti., Venkata S. R. Krishna., & Tom Schwenk, (2003), J2EE Developer's Handbook Sams Publications, New Delhi, 1" Edition. 5. Rod Johnson. (2004), J2EE Development without EJB , New Delhi: Wiley Dream Tech, 1% Edition 6. Rod Johnson., & Rod Johnson, P.H. (2004). Expert One-On-One J2ee Design and Development. New Delhi: John Wiley & Sons, 2" Edition, 7. Budi Kumiawan (2012), Servlet & JSP: A Tutorial, Brainy Software Publisher, 1* Edition. Department of CS, CA & IT, KAHE 2 J2EE 2016- 2018 Batch 8, Mahesh P. Matha (2013), JSP and SERVLETS: A Comprehensive Study PHI Learning, 1% Edition. 9. John Brock, Arun Gupta, Geertjan Wielenga (2014), Java EE and HTMLS Enterprise Application Development Oracle Press. WEB SITES www java.sun.com/javaee! ‘www java.sun.com/j2ee/1 4/does/tutorial/doc/ www j2eebrain.com/ www javaworld.com/ www.corej2eepatterns.com/ www jsptut.com avaene Department of CS, CA & IT, KAHE 3 Lecturer Plan | 2016- g ;. KARPAGAM ACADEMY OF HIGHER EDUCATION “| J} (Deemed University Established Under Section 3 of UGC Act 1956) Sones Coimbatore ~ 641 021 en (For the candidates admitted from 2016 onwards) DEPARTMENT OF COMPUTER SCIENCE Faculty Name —_Dr.S.Manju Priya Subject WEE Subject Code 16CSP301 Class IL M.Sc Computer Science Semester atte Batch 2016-2018 LECTURER PLAN Lecture " . Support SLNo | Duration Topics to be Covered Materials (Hrs) 1 2 Beginning of Java, Java Byte code Advantages of Java | T1: 8-15 2 1 J2EE and J2SE_ TI: 16-20 3 2 J2EE Multi Tier Architecture , Distributive Systems Ti: 24-27 4 1 The Tire, Multi tier architecture TI: 27-32 5 1 Client Tier Ti: 32-33 6 1 Web Tier Ti: 33-34 7 2 Enterprise Java Beans Tier Enterprise TI: 35-36, 8 1 Information Systems ‘Tier Implementation, Th: 36-37 9 1 Recapitulation and Discussion of Important Questions Total Hrs Planned for Unit I 12 Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Lecturer Plan | 2016 UNIT IT Lecture Support SLNO | Duration Topics to be Covered upp Materials (Hrs) 1 2 J2EE Database Concepts: Data ~ Database T1:98-99 2 2 Database schema T1:100-115 3 2 JDBC Objects: Driver Types Packages Th124-126 4 2 JDBC Process Database Connection TH:127-133 5 2 Statement Objects Result Set T1:135-148 6 2 Meta Data T1:157-160 1 1 Recapitulation and Discussion of Important Questions ‘Total Hrs Planned for Unit 11 13 UNIT OL Lecture Support SLNO | Duration Topics to be Covered PPO Materials (Hrs) 1 1 Java Servlets:Benefits 11:350 2 3 Anatomy 11:352-354 3 1 Reading Data from Client T1354 4 1 Reading HTTP Request Headers 11355 3 2 Sending Data to client T1359 6 1 Working with Cookies T1:361-364 1 1 Recapitulation and Discussion of Important Questions ‘Total Hrs Planned for Unit II 10 Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Lecturer Plan | 2016 UNIT IV, Lecture support SLNO | Duration Topics to be Covered M. PPO aterials (Hrs) 1 1 Enterprise Java Beans: Deployment Descriptors T1:409-424 2 2 Contd... Deployment Descriptors T1:409-424 3 2 Session Java Bean T1:431-433 4 1 Entity Java Bean T1:434-439 5 2 Message Driven Bean T1:440-443 6 1 Recapitulation and Discussion of Important Questions ‘Total Hrs Planned for Unit IV 9 UNIT V Lecture Support SLNO | Duration Topics to be Covered mpPo! Materials (Hrs) JSP: What is Java Server Pages? - Evolution of Dynamic 1 2 __| Content Technologies 11:379-381 2 1__| JSP & Java 2 Enterprise T2:2-15 ISP Fundamentals: Writing your first JSP- Tag Ti: 381-389 3 2___| conversions,Running JSP Ri: 44-87 4 2___| Programming ISP Scripts: Scripting Languages T2:46-64 5 2__| JSP tags- JSP directives Ti: 381-388 6 1 Scripting elements , Flow of Control comments 12:65-82 1 2___| Java Remote Method Invocation T1: 486-489 Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Lecturer Plan | 2016. 8 1 Recapitulation and Discussion of Important Questions 9 1 Discussion of Previous ESE Question Papers 10 1 Discussion of Previous ESE Question Papers u 1 Discussion of Previous ESE Question Papers ‘Total Hrs Planned for Unit V 16 Total Hrs 60 Text Book TI | Jim Keogh. (2010). The Complete Reference J2EE, Tata McGraw Hill: New Delhi. Ist Edition. Duane K. Fields & Mark A-Kolb.(2002) Web Development with Java Server TI | Pages, Ist Edition, Manning Publications, Pune References David R. Heffelfinger (2011), Java EE 6 Development with NetBeans 7,Packt Publishers, Ist R1_| Edition, Joel Murach, Michael Urban, (2014), Murach’s Java Servlets and JSP, (Murach: Training & R2_| Reference). 3rd Edition R3 | Joseph, J. Bambara et al. (2007). J2EE Unleashed , New Delhi:Tech Media, Ist Edition Paul, J, Perrone., Venkata, S. R. Chaganti., Venkata S. R. Krishna., & Tom Schwenk, (2003), R4_| J2EE Developer's Handbook, Sams Publications, New Delhi, 1st Edition Rod Johnson. (2004). J2EE Development without EJB , New Delhi: Wiley Dream Tech, Ist RS _| Edition, Rod Johnson., & Rod Johnson, P.H. (2004). Expert One-On-One J2ee Design and Development. R6_| New Delhi: John Wiley & Sons, 2nd Editio R7_| Budi Kurniawan (2012), Servlet & JSP: A Tutorial, Brainy Software Publisher, lst Edition. Mahesh P. Matha (2013), JSP and SERVLETS: A Comprehensive Study PHI Learning, R8_| Ist Edition, John Brock, Arun Gupta, Geertjan Wielenga (2014), Java EE and HTMLS Enterprise Application R9_| Development Oracle Press. Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Lecturer Plan | 2016-2018 Batch Web Sites W1_| java.sun.com/javace/ W2 | java.sun.comy/j2ee/1.4/docs/tutoria/doc W3 | www.j2eebrain.com/ Wa | www javaworld.com/ WS | www.corej2eepatterns.com/ Wo | www jsptut.com Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE J2EE Overv UNIT I J2EE Overview: Beginning of Java — Java Byte code — Advantages of Java —I2EE and J2SE. .2EE Multi Tier Architecture — Distributive Systems — The Tier — Multi Tier Architecture — Client Tier - Web Tier - Enterprise Java Beans Tier - Enterprise Information Systems Tier Implementation. TEXT BOOKS 1. Jim Keogh. (2010). The Complete Reference J2EE, Tata McGraw Hill: New Delhi. 1st Edition, REFERENCES 1. David R. Heffelfinger (2011), Java EE 6 Development with NetBeans 7,Packt Publishers,1* Edition. 2. Paul, J. Pettone., Venkata, S. R. Chaganti., Venkata $. R. Krishna., & Tom Schwenk, (2003), J2EE Developer's Handbook Sams Publications, New Delhi, 1* Edition 3. Rod Johnson. (2004). J2EE Development without EJB , New Delhi: Wiley Dream Tech, 1* Edition 4, Rod Johnson. & Rod Johnson, P.H. (2004). Expert One-On-One J2ee Design and Development. New Delhi: John Wiley & Sons, 2" Edition. WEB SITES www. java.sun.comijavace/ www java.sun.com/j2ee/1.4/docs/tutorial/doc/ www, eebrain.com’ www, javaworld.com/ www. corej2eepattemns.com! weepe Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 1/15 2016-2018 Batch J2EE OVERVIEW IQEE is Java, optimized for enterprise computing. Officially J2EE stands for Java 2 Platform, Enterprise Edition, J2EE is an open, standard-based, development and deployment platform for building n-tier, web-based and server-centric and component-based enterprise applications. As an enterprise platform, the J2EE environment extends basic Java with tools that "provide a complete, stable, secure, and fast Java platform to the enterprise level." One goal of using J2EE is reducing the cost and complexity of creating large-scale solutions. Because Java is a strongly typed language, use of the language is often inherently more secure in Web applications than Web applications built with less strong typing 1.1 BEGINNING OF JAVA Java was created in 1991. It was developed by James Gosling et al. of Sun Microsystems. Initially called Oak, in honor of the tree outside Gosling's window, its name was changed to Java because there was already a language called Oak. The original motivation for Java is the need for platform independent language that could be embedded in various consumer electronic products like toasters and refrigerators. As a programming language, Java can create all kinds of applications that you could create using any conventional programming language 1.2 JAVA BYTE CODE Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode opcode is one byte in length, although some require parameters, resulting in some multi-byte instructions. Not all of the possible 256 opcodes are used. Java bytecode is designed to be executed in a Java virtual machine, There are several virtual machines available today, both free and commercial products. Fig.1.1 shows the process of converting a source code to byte code. Java Source Code | —>} Interpreter. | —>} Java Byte Code Fig. 1.1 Converting Source code to bytecode Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 2/15 2016-2018 Batch 1.3 ADVANTAGES OF JAVA JAVA offers a number of advantages to developers. «Java is simple: Java was designed to be easy (0 use and is therefore easy to write, compile, debug, and lear than other programming languages. The reason that why Java is much simpler than C-+ is because Java uses automatic memory allocation and garbage collection where else C++ requires the programmer to allocate memory and to collect garbage + Jaya is object-oriented: Java is object-oriented because programming in Java is centered on creating objects, manipulating objects, and making objects work together. This allows you to create modular programs and reusable code. + Java is platform-independent: One of the most significant advantages of Java is its ability to move easily fom one computer system to another. The ability to run the same program on many different systems is crucial to World Wide Web software, and Java succeeds at this by being platform-independent at both the source and binary levels. Java is distributed: Distributed computing involves several computers on a network working together. Java is designed to make distributed computing easy with the networking capability that is inherently integrated into it. Writing network programs in Java is like sending and receiving data to and from a file, For example, the diagram below shows three programs running on three different systems, communicating with each other to perform a joint task. ‘+ Java is interpreted: An interpreter is needed in order to run Java programs. The programs are compiled into Java Virtual Machine code called bytecode. The bytecode is machine independent and is able to run on any machine that has a Java interpreter. With Java, the program need only be compiled once, and the bytecode generated by the Java compiler can run on any platform. + Jaya is secure: Java is one of the first programming languages to consider security as part of its design. The Java language, compiler, interpreter, and runtime environment were each developed with security in mind. Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 3/15 2016-2018 Batch «Java is robust: Robust means reliable and no programming language can really assure reliability. Java puts a lot of emphasis on early checking for possible errors, as Java compilers are able to detect many problems that would first show up during execution time in other languages. ‘+ Java is multithreaded: Multithreaded is the capability for a program to perform several tasks simultaneously within a program. In Java, multithreaded programming has been smoothly integrated into it, while in other languages, operating system-specific procedures have to be called in order to enable multithreading. Multithreading is a necessity in visual and network programming 1.4 J2EE AND J2SE RSE is considered the foundation edition of the Java platform and programming environment in which all other editions are based. J2EE is the edition of the Java 2 platform targeted at developing multi-tier enterprise applications.J2EE consists of a set of specifications, APIs and technologies defining enterpris application development. J2EE technology providers expose tools, frameworks and platforms that handle a good deal of the details of enterprise application infrastructure and behavior. J2EE implementations enjoy all of the features of the Java 2 Standard Edition (J2SE) platform with additional frameworks and libraries added to support distributed/Web development 1.5 J2EE MULTI TIER ARCHITECTURE ‘The J2EE platform uses a multitiered distributed application model. Application logic is divided into components according to function, and the various application components that make up a REE application are installed on different machines depending on the tier in the multitiered REE environment to which the application component belongs. Figure 1.2 shows two multitiered J2EE applications divided into the tiers described in the following list. ‘* Client-tier components run on the client machine, ‘+ Web-tier components run on the J2EE server ‘+ Enterprise JavaBean tier components run on the J2EE server. Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 4/15 J2QEE Overview | 2016- 2018 Batch ‘© Enterprise information system (EIS)-tier software runs on the EIS server. Although a J2EE application can consist of the three or four tiers shown in Figure 1.2, J2EE ‘multtiered applications are generally considered to be three tiered applications because they are distributed over three different locations: client machines, the JER. server machine, and the database or legacy machines at the back end, Three-tiered applications that run in this way extend the standard two-tiered client and server model by placing a multithreaded application server between the client application and back-end storage, soslesiont — Aopston 2 Se | ctant ie ea i woo. Ter | eee e Machine Business ‘Ter Es ao Ter | Machine Figure1.2 J2EE Multitiered Applications 1.6 DISTRIBUTIVE SYSTEMS The concept of multi-tier architecture has evolved over decades, following a similar evolutionary course as programming languages. The key objective of multi-tier architecture is to share resources amongst clients, which are the fundamental design philosophy used to develop programs. In earlier days programmers originally used assembly language to create programs. These programs employed the concept of software services that were shared with the program running on the machine, Software services consist of subroutines written in assembly language that communicate with each other using machine registers, which are memory spaces within the CPU of a machine. Whenever a programmer required functionality provided by a software Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 5/15 2016-2018 Batch service, the programmer called the appropriate assembly language subroutine from within the program. Although the technique of using software services made creating programs efficient by reusing code, there was a drawback. Assembly language subroutines were machine specific and couldn't be easily replicated on different machines, This meant that subroutines had to be rewritten for each machine. The introduction of FORTRAN and COBOL brought the next evolution of programming languages and with it the next evolution of software services. Programs written in FORTRAN could share functionality by using functions instead of assembly language subroutines. The same was true of programs written in COBOL. A function is conceptually similar to a Java method, which is a group of statements that perform a specific functionalit y. The group is named, and is callable from within a program. Although both assembly language subroutines and functions are executed in a single memory space, functions had a critical advantage over assembly language subroutines. ‘A function could run on different machines by recompiling the function, However, software services were restricted to a machine. This meant programs and functions that comprise software services had to reside on the same machine. A program couldn't call a software service that was contained on a different machine. Programs and software services were saddled with the same limitations that affected data exchange at that time. Magnetic tapes were used to transfer data, programs, and software services to another machine. There wasn’t a real-time transmission system, 1.7 THE TIER A tier is an abstract concept that defines a group of technologies that provide one or more services to its clients. A good way to understand a tier structure’s organization is to draw a parallel to a typical large corporation (see Figure 1.3) Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 6/15 J2EE Overview | 2016- 2018 Batch Martoing Ter [ [_Pradt Namapemont Varker Reveach Froctucton Ter [ [Manatactaring ) [Profuct Design) [Pures supporter [ [Accoantne) (Supplies) [Corman Faolities| [Eketreig) [Ventiaton| Services Tit ([Friphone Servis] Figure 1.3 Resources of a large organization are typically organized into a tier structure that operates similarly to the tier structure used in distributed systems, At the lowest level of a corporation are facilities services that consist of resources necessary to maintain the office building. Facilities services encompass a wide variety of resources that typically include electricity, ventilation, elevator services, computer network services, and telephone services. The next tier in the organization contains support resources such as accounting, supplies, computer programming, and other resources that support the main activity of the company. Above the support tier is the production tier. The production tier has the resources necessary to produce products and services sold by the company. The highest tier is the marketing tier, which consists of resources used to determine the products and services to sell to customers Any resource is considered a client when a resource sends a request for service to a service provider (also referred to as a service). A service is any resource that receives and fulfills a request from a client, and that resource itself might have to make requests to other resources to fulfill a client’s request. For Example a product manager working at the marketing tier decides the company could make a profit by selling customers a widget. The product manager requests an accountant to conduct a formal cost analysis of manufacturing a widget. The accountant is on the support tier of the organization. The product manager is the client and the accountant is the service. However, the accountant requires information from the manufacturing manager to fulfill the product manager's request. The manufacturing manager works on the production tier of the organization, The accountant is the client to the Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 7/15 2016-2018 Batch ‘manufacturing manager who is the service to the accountant, In multi-tier architecture, each tier contains services that include software objects, database management systems (DBMS), or connectivity to legacy systems. Information technology departments of corporations employ multi-tier architecture because it’s a cost-efficient way to build an application that is flexible, scalable, and responsive to the expectations of clients. This is because the functionality of the application is divided into logical components that are associated with a tier. Each component is a service that is built and maintained independently of other services. Services are bound together by a communication protocol that enables a service to receive and send information from and to other servic: A client is concerned about sending a request for service and receiving results from a service. ‘A client isn’t concerned about how a service provides the results. This means that a programmer can quickly develop a system by creating a client program that formulates requests for services that already exist in the multi-tier architecture. These services already have the functionality built into them to fulfill the request made by the client program. Services can be modified as changes oceur in the functionality without aff ting the client program. For example, a client might request the tax owed on a specific order. The request is sent to a service that has the functionality to determine the tax. The business logic for calculating the tax resides within the service. A programmer can modify the business logic in the service to reflect the latest changes in the tax code without having to modify the client program. These changes are hidden from the client program. 1.8 J2EE MULTI-TIER ARCHITECTURE RE is fourier architecture (see Figure!.4). These consist of the Client Tier (sometimes referred to as the Presentation Tier or Application Tier), Web Tier, Enterprise JavaBeans Tier (sometimes referred to as the Business Tier), and the Enterprise Information Systems Tier. Each tier is focused on providing a specific type of functionality to an application.{t's important to delineate between physical location and functionality. Two or more tiers can physically reside on the same Java Virtual Machine (JVM) although each tier provides a different type of functionality to a J2EE application. And since the J2EE multi-tier architecture is functionally centric, a J2EE application accesses only tiers whose functionality is required by the 2EE Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 8/15 2016-2018 Batch application. It’s also important to disassociate a J2EE API with a particular tier. That is, some APIs (i.e., XML API) and J2EE components can be used on more than one tier, while other APIS (ie., Enterprise JavaBeans API) are associated with a particular tier. The Client Tier consists of programs that interact with the user. ‘These programs prompt the user for input and then convert the user's response into requests that are forwarded to software on a component that processes the request and returns results to the client program. The component can operate on any tier, although most requests from clients are processed by components on the Web Tier. The client program also translates the server's response into text and screens that are presented to the user. Cent ter | [Component } [Component | [Component } [ Component Web ier | [Component } [Component } [Component } [Component “nteeprise JavaBeans Tir | [Component } [Component | [Component } [Component Enterprise formation Systems Tier| [ Component] [ Component] [Component | [ Compare Figurel.4 J2EE consists of four tiers, each of which focuses on providing specific functionality to an application, The Web Tier provides Intemet fimctionality to a J2EE application, Components that operate on the Web Tier use HTTP to receive requests from and send responses to clients that could reside on any tier. A client is any component that initiates a request, as explained previously in this chapter. For example (see Figure 1.5), a client’s request for data that is received by a component working on the Web Tier is passed by the component to the Enterprise JavaBeans Tier where an Enterprise Java Bean working on the Enterprise JavaBeans Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 9/15 2016-2018 Batch Cen er | [Conpoent} [Comparer] [Conporent) [Component Reply rept ab ta | [Carponent] [Component] [Compara] [Compone Reply {a request Ecupin aba | [Cape] [Gossent][ EB _ | [Gp ™ teereenomatn | (Ceca [Compa] [Cope] [_ ORS Figure 1.5 J2EE consists of four tiers, each of which focuses on providing specific functionality to an application ‘A request is typically passed from one tier to another before the Tier interacts with DBMS to fulfill the request. Requests are made to the Enterprise JavaBeans by using the Java Remote Method Invocation (RMI) API. The requested data is then returned by the Enterprise JavaBeans where the data is then forwarded to the Web Tier and then relayed to the Client Tier where the data is presented to the user. The Enterprise JavaBeans Tier contains the business logic for J2EE applications. Access is made using an Access Control List (ACL) that controls communication between tiers, The ACL is a critical design element in the J2EE multictier architecture because ACL bridges tiers that are typically located on different virtual local area networks and because ACL adds a security level to web applications, Hackers typically focus their attack on the Web Tier to try to directly access DBMS. ACL prevents direct access to DBMS and similar resources. The EIS links a J2EE application to resources and legacy systems that are available on the corporate backbone network. It’s on the EIS where a J2EE application directly or indirectly interfaces with a variety of technologies, including DBMS and mainframes that are part of the mission-critical systems that keep the corporation operational, Components that work on the EIS communicate to resources using CORBA or Java connectors, referred to as J2EE Connector Extensions. Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 10/15 2016-2018 Batch 1.9 CLIENT TIER IMPLEMENTATION ‘There are two components on the Client Tier that are described in the J2EE specification. These are applet clients and application clients. An applet client is a component used by a web client that operates within the applet container, which is a Java-enabled browser. An applet uses the browser as a user interface. ‘An application client is a Java application that operates within the application client container, which is the Java 2 Runtime Environment, Standard Edition (JRE). An application has its own user interface and is capable of accessing all the tiers in the multi-tier architecture depending how the ACLs are configured, although typically an application has ace: s to only the web layer. A rich client is a third type of client, but a rich client is not considered a component of the Client Tier because a rich client can be written in a language other than Java and therefore J2EE doesn’t define a rich client container. ‘A rich client is similar to an application client in that both are applications that contain their own user interface, And as with an application client, a rich elient can access any tier in the environment, depending on the ACLs configuration, using HTTP, SOAP, ebXML, or an appropriate protocol. 1,10 WEB TIER IMPLEMENTATION ‘The Web Tier has several responsibilities in the J2EE multi-tier architecture, all of which is provided to the Client Tier using HTTP, These responsibilities are to act as an intermediary between components working on the Web Tier and other tiers and the Client Tier. Intermediary activities include: ‘© Accepting requests from other software that was sent using POST, GET, and PUT operations, which are part of HTTP transmissions ‘* Transmit data such as images and dynamic content There are two types of components that work on the Web Tier. These are servlets and Java Server Pages (JSP), although many times they are proxied to the Application or EJB Tier. A servlet is a Java class that resides on the Web Tier and is called by a request from a browser Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 11/15 2016-2018 Batch client that operates on the Client Tier. A servlet is associated with a URL that is mapped by the servlet container. A request for a servlet contains the servlet’s URL and is transmitted from the Client Tier to the Web Tier using HTTP. The request generates an instance of the servlet or reuses an existing instance, which receives any input parameters from the Web Tier that are necessary for the servlet to perform the service. Input parameters are sent as part of the request from the client. An instance of a servlet fulfills the request by accessing components/resources on the Web Tier or on other tiers as is necessary based on the business logic that is encoded into the servlet. The servlet typically generates an HTML output stream that is returned to the web server. The web server then transmits the data to the client, This output stream is a dynamic web page. ISP is similar to a servlet in that a JSP is associated with a URL and is callable from a client However, JSP is different than a servlet in several ways, depending on the container that is used. Some containers translate the JSP into a servlet the first time the client calls the JSP, which is then compiled and the compiled servlet loaded into memory. The servlet remains in memory. Subsequent calls by the client to the JSP cause the web server to recall the servlet without translating the JSP and compiling the resulting code. Other containers precompile a JSP into a .java file that looks like a servlet file, which is then compiled into a Java class. Business logic used by JSP and servlet’s is contained in one or more Enterprise JavaBeans that are callable from within the JSP and servlet, The code is the same for both JSP and servlet, although the format of the code differs. JSP uses custom tags to ac s an Enterprise JavaBeans while servlet’s are able to directly access Enterprise JavaBeans. 1.11 ENTERPRISE JAVABEANS TER IMPLEMENTA’ rION 21 uses distributive object technology to enable Java developers to build portable, scalable, and efficient applications that meet the 24-7 durability expected from an enterprise system. The Enterprise JavaBeans Tier contains the Enterprise JavaBeans server, which is the Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 12/15 2016-2018 Batch object server that stores and manages Enterprise JavaBeans. The Enterprise JavaBeans Tier is a vital element in the J2EE multi-tier architecture because this tier provides concurrency, scalability, lifecycle management, and fault tolerance. The Enterprise JavaBeans Tier automatically handles concurrency issues that assure multiple clients have simultaneous access to the same object. The Enterprise JavaBeans Tier is the tier where some vendors include features that enable scalability of an application, because the tier is designed to work in a clustered environment, This assumes that vendor c mponents that are used support clustering. If not, a Local Director is typically used for horizontal load balancing The Enterprise JavaBeans Tier manages instances of components. This means component containers working on the Enterprise JavaBeans Tier create and destroy instances of components and also move components in and out of memory. Fault-tolerance is an important consideration in mission-critical applications. The Enterprise JavaBeans Tier is the tier where some vendors include features that provide fault-tolerant operation by making it possible to have multiple E {terprise JavaBeans servers available through the tier. This means backup Enterprise JavaBeans servers can be contacted immediately upon the failure of the primary Enterprise JavaBeans server. The Enterprise JavaBeans server has an Enterprise JavaBeans container within which is @ collection of Enterprise JavaBeans. As discussed in previous sections of this chapter, an Enterprise Java Bean is a class that contains business logic and is callable from a servlet or JSP. Collectively the Enterprise JavaBeans server and Enterprise JavaBeans container are responsible for low-level system services that are required to implement business logic of an Enterprise Java Bean, These system services are = Resource pooling 1m Distributed object protocols = Thread management m State management m Process management = Object persistence Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 13/15 2016-2018 Batch m Security m Deploy-time configuration A key benefit of using the Enterprise JavaBeans server and Enterprise JavaBeans container technology is that this technology makes proper use of a programmer's expertise, That is, a programmer who specializes in coding business logic isn’t concerned about coding system services. Likewise, a programmer whose specialty is system servi s can focus on developing system services and not be concemed with coding business logic. Any component, regardless of the tier where the component is located, can use Enterprise JavaBeans. This means that an Enterprise Java Bean client can reside outside the Client Tier. The protocol used to communicate between the Enterprise JavaBeans Tier and other tiers is dependent on the protocol used by the other tier. Components on the Client Tier and the Web ‘Tier communicate with the Enterprise JavaBeans Tier using the Java RMI API and either OP or IRMP. Sometimes software on other tiers, usually the middle tier, uses JMS to communicate with the Enterprise JavaBeans Tier. This communication isn’t exclusively used to send and receive messages between machines. IMS js also used for other communication, such as decoupling tiers using the queue mechanism. However, the Enterprise Java Bean that is used must be a message- ‘pourgus0) paurguios aIseq stoumgag | jonuoy siseg | srommfog aise SETAE Jo worsuedya oy TOMSUY] pido endo zado ado) SuOHsend 1uiNa soPsW: — ssvID logdso91 ‘envy pue sjonpoxd| lav “WAX ast ard lav SINE [ePorounOD Hoayi9g soaRFLO}UE “yauias eae e ast AWWLH (P ast ara ean _ | ow parejsuen Aqjeonewomne st wiesfioxd ———_ y Pave 2109 ace asc awer payieo st eaey Jo worep yeurts0 94.1 Ajsnoauey nus wesBord ures yp 0} ssa90e 9jdiyfnun usrod pu sassas0ud o1p0 wos peanp peasy onouny ampacond oxoeut ymapuiadapur 20a ue yep ssag0nd vst ¥ poruon0 papearyninus ampacord | papearprrnus | aurysermnur sasnn mu aenduey Suyurusestoad ———— v st eae ‘urwoy yuouidoyaaap eave amp £q) 19 pure 9. totems, | 449 pued Aquo 49 avy uy pardope azn ut punog saamyeog| suonouny sat SOdt suonouny siaqAzas ‘S20 Mas axeMyos yeusayuy ayy are uoneuassidoy | uoneuosaidsy | onewosaidsy | uoneuasoidoy uonemasordoy meq revaiq meq meq ered feurorxg remtounsadyg, [earorxg, earn afueyoxg SEA 0 worsuedxo on, aamDoIY amoaNySTy onda, ysonbay | oiseg isonboy aayorg sanboy | otseg ysanbay 9afo 19a algo spafqo wourues | y9afq wounwo peuiqwoy wou) pauiquoy, SL VERO) Jo worsueda ayy sash sug SaSf pur siopwros._| pue siayazas wary sap pue avy pre ay ‘Suwa exee ‘sueag eave | stajatos eae | siayaros ener | stag wane ale ZA Zf Jo Stusuodutos 109 a4, areMa|PpIUH paquaio soureu09 29urE]U09 SWE lav -offessour sw _| 1arssuorssos ayy &q parte st unag uoaLsp-afessour y oIssos oIssos ‘yle> porjau usamaq orssos ssayarers | soureruoo SWE myers eis _faparas worssos ares Aue urmuren you soop weagq_____¥ woIssos oIssos aN9 B YMA WOISSDS| morssas rgarers | sourert0o SWE ssoyarers rryareis _fajaras worssas |e Surmp poreynumaoe erep surpjar ung ¥| sroaias suorearjdde wo uns 0} pouiisop| susuoduoo ssousng apis-194r9s a{qesnos Surdoyas9p} ara eae seyrag ast ara 104 Sfa¥ pu suoneaytoads Jo sjsisuos | sears dst widdy anjo09, wIseg FoAaS au Wo Sopisar yeyp tuwsord v st cuoneoydde 1377 wn sia sen af en quay © 0} Aueuoryouny touionuy saprnoid a4 ssn oqp (pM ayo sta on aa qm wor | _roera1ut ye stuesoxd Jo systsuoo 18» ——_q ‘uonwoydde a2rzr e oy Ajeuonauny| Jo adK jusrayp e sapiaoid san Yee YBNoWTe WAL € t € z alues ayy wo apisar Kjeaisiyd uea sian | ¢ s + € z ‘aunyaoytyie ioe saz ‘a01a1as Waysks ypIM WatioduoD v sepisoud pue} s9ure 409 atasos samosas | quouodwioa ofleueu yey) oxeayos ® st VI sataros v aplaoudl samnosaz rasos aoinosor | _yuouoduioa spurey09 01 spoau juouodunos e Surpdue stv soa.aios auf aplaoid 0) uonoury sutioysod ywxp wweafioud e 40 sasso Jo wor}99II09) qwouoduroo 2onsas soanosor_| _quouioduro soupentos bo sisistoo yyy son v jo ued e st | ‘suaisks Kova suresfoxd 04 Ayyanaouuoa 10 SWVEICT ‘si90{go axeaxyos apnyout FEM) soayaios sisonbar srapaias anf seoqaias_ | sareyuoo s9n yoee ‘ammyoayqyue sony-nynud uy sodu sdst soa suonoury sjajaras Sa9]AI98 BANJOS [PILIOIXD amp a1 yuot}o omoouyoe x9n-nyNUE 9yp UF SION aA [Te BuNss90e uoneandde wires | uoneoydde | wuayforajdde | _woneondde Jo aqqedea st pur aoeyzanar wo sit sey ¥ UOHIp plpuRg jaUITOAANG SuHUNy wo Z ABP amp St Yor “louIMUOD ToH]a woNeOHdde arp] oy]9 onward dst royaros_ | anon vajdde | onesrdde | argu soresodo yeu woneandde eavl v stv “osmouq payqeta way eae e st yoy Youre U0 jaydde aqy UIE sarezado way vide dst rasies_| quays aydde | _uoneondde seyy Ways qaas & Aq pasn quouoduos & st v t s + € Z_| 29m quay amp wo sytauoduros ———— ae aon saugFUTEM pue SWIC BuIpnyoUr SorFofouysay| Jo Ayana e qn saaepanuy Ksauput 10 Ap.29N1p sureafioad qu9119 ast ara sio|Az08 ide aazr B a19y8 a uo stay “91 Gd tp Wo SH10% FeYT 1aAI98 199"Go pamnqunsip © ara__| suresfiosd jaro ast ara sisas | stupas s9atos gra amp wo poureyuos ame ~— | cuoneardde| en ara, sta son ara gem way} ACL Atan9 0} auiorsKoy amp st 19>. splomjou auoqyseq aresodioa ap uo ayqepreae axe wey suioysks Koefiay pure sia sta en ara gem saoanosas 01 uoneondde qarzr e SAuHL on aL ‘suonvoydde son aa sta on aa gam wor _ | gaze soy a180y ssoursng oy sureuos son —— 4 z ofa ways gear shay]9 gam oF eyes are sad ways zante | awors xonnyc ano sia | _awous ara awayja gam _ | sores game o1 seyuns étpensdoati0g are saad “Fan gam aq] Wo SHi0M eM AoKAIAS v osye] read 201aras qam aus qe, quo sia | qwoup aa auayja gam | _ staf asneaaq quota yo addy anbyun v si | “a SI aH to parevot saaanosas| suanja sia | uot sia | wou ara pe stosn oanyoq aoepsoyut ayy ase — | 0H gam aq uo saamnosar wey) soureL s9n Sera ayn uo pareaoy| wows eirat_| uo won sia | qwou era auoyja gaa | ame yey AF ax0U 10 uo sassagoe Ajo | “a1 gam ayy Uo pareso] ssanosar sassa0ae eH} waryo goat spnnynut quayja qa | _sosmorg e Aqjonsn areaujos jo sistsuoa | b s b € z sodé1 ont parpisseyo ze syuat19} 29 “dVOS| ‘ALLH Sursn vonemagquos sToy 9% wo Supuadap) way yous weraas war your | way raidde | woneordde | yuaumuosjaue ayy ut ian Aue ssaoae wea v| wo1}> “ian wor amp tayo your Joaras auayo yor | aways safdde | wonesrtdde | yo tuouodaros ayp se parapisuoa you st ¥ J2EE Database Concepts 2016- 2018 Batch UNITII J2EE Database Concepts: Data — Database — Data — Packages — JDBC Process ~ Database Connection — Statement Objects — Result Set — Meta ase Schema, JDBC Objects: Driver Types Data, TEXT BOOKS 1. Jim Keogh. (2010). The Complete Reference J2EE, Tata McGraw Hill: New Delhi. 1st Edition, REFERENCES 1. David R. Heffelfinger (2011), Java EE 6 Development with NetBeans 7,Packt Publishers,1" Edition. 2. Joel Murach, Michael Urban, (2014), Murach's Java Servlets and JSP, (Murach: Training & Reference). 3rd Edition Joseph, J. Bambara et al. (2007). J2EE Unleashed , New Delhi: Tech Media, 1* Edition. 4, Paul, J. Perrone., Venkata, S. R. Chaganti., Venkata S. R. Krishna., & Tom Schwenk, (2003), J2EE Developer's Handbook Sams Publications, New Delhi, 1* Edition, 5. Rod Johnson, (2004), J2EE Development without EJB , New Delhi:Wiley Dream Tech, 1* Edition 6, Rod Johnson. & Rod Johnson, PH. (2004). Expert One-On-One J2ee Design and Development. New Delhi: John Wiley & Sons, 2™ Edition. 7, John Brock, Arun Gupta, Geertjan Wielenga (2014), Java EE and HTMLS Enterprise Application Development ,Oracle Press. WEB SITES 1. www java.sun.com/javace! www java.sun.com/j2ee/1.4/does/tutorialidoc! www.j2eebrain.com! www javaworld.com/ wake www.corej2eepatterns.com! Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 1/24 J2EE Database Concepts 2016- 2018 Batch J2EE DATABASE CONCEPTS 2.1 DATA The term data means groups of information that represent the qualitative or quantitative attributes of a variable or set of variables. Data (plural of "datum") are typically the results of measurements and can be the basis of graphs, images, or observations of a set of variables. Data are often viewed as the lowest level of abstraction from which information and knowledge are derived. In computer science, data is anything in a form suitable for use with a computer. Data is often distinguished from programs. Data is a collection of facts, figures and statistics related to an object. Data can be processed to create usefill information. Data is a valuable asset for an organization. Data can be used by the managers to perform effective and successful operations of ‘management. It provides a view of past activities related to the rise and fall of an organization, It also enables the user to make better decision for future. Data is very useful for generating reports, graphs and statistics Example: Students fill an admission form when they get admission in college. The form consists of raw facts about the students, These raw facts are student's name, father name, address ete, The purpose of collecting this data is to maintain the records of the students during their study period in the college. 2.2 DATABASE A database is an integrated collection of logically related records or files consolidated into a common pool that provides data for one or more multiple uses. One way of classifying databases involves the type of content, for example: bibliographic, full-text, numeric, and image. Software organizes the data in a database according to a database model. A number of database architectures exist. Many databases use a combination of strategies. Databases consist of software-based "containers" that are structured to collect and store information so users can retrieve, add, update or remove such information in an automatic fashion. Database programs are designed for users so that they can add or delete any information needed. The structure of a database is the table, which consists of rows and columns of information, Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 2/24 J2EE Database Concepts 2016- 2018 Batch 2.3 DATABASE SCHEMA ‘The schema of a database system is its structure described in a formal language supported by the database management system (DBMS). In a relational database, the schema defines the tables, the fields, relationships, views, indexes, packages, procedures, functions, queues, triggers, types, sequences, materialized views, synonyms, database links, directories, Java, XML schemas, and other elements, Schemas are generally stored in a data dictionary. Although a schema is defined in text database language, the term is often used to refer to a graphical depiction of the database structure Levels of database schema ‘+ Conceptual schema, a map of concepts and their relationships. + Logical schema, a map of entities and their attributes and relations + Physical schema, a particular implementation of a logical schema + Schema object, Oracle database object 2.3.1 Conceptual schema A conceptual schema or conceptual data model is a map of concepts and their relationships. This describes the semantics of an organization and represents a series of assertions about its nature. Specifically, it describes the things of significance to an organization (entity classes), about which it is inclined to collect information, and characteristics of (attributes) and associations between pairs of those things of significance (relationships). 2.3.2 Logical schema ‘A Logical Schema is a data model of a specific problem domain expressed in terms of a particular data management technology. Without being specific to a particular database management product, it is in terms of relational tables and columns, object-oriented classes, or XML tags. This is as opposed to a conceptual data model, which describes the semantics of an organization without reference to technology, or a physical data model, which describe the particular physical mechanisms used to capture data in a storage medium. The next step in creating a database, after the logical schema is produced, is to create the physical schema. ical Schema 2.3.3 Phy Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 3/24 J2EE Database Concepts 2016- 2018 Batch Physical Schema is a term used in relation to data management. In the ANSI four-schema architecture, the internal schema was the view of data that involved data management technology. This was as opposed to the external schema that reflected the view of each person in the organization, or the conceptual schema that was the integration of a set of external schemas. 2.3.4 Schema Object A schema object is a logical data storage structure. Schema objects do not have a one-to-one correspondence to physical files on disk that store their information. However, Oracle stores a schema object logically within a table space of the database. The data of each object is physically contained in one or more of the table space's data files. For some objects such as tables, indexes, and clusters, you can specify how much disk space Oracle allocates for the object within the table space’s data files. There is no relationship between schemas and table spaces: a table space can contain objects from different schemas, and the objects for a schema can be contained in different table spaces. Associated with each database user is a schema, A schema is a collection of schema objects. Examples of schema objects include tables, views, sequences, synonyms, indexes, clusters, database links, snapshots, procedures, functions, and packages, 2.4 INTRODUCTION TO JDBC An application programming Interface (API) is a set of classes, methods and resources that programs can use to do their work. APIs exist for windowing systems, file systems, database systems, networking systems, and others. JDBC is a Java API for database connectivity that is part of the Java API developed by Sun Microsystems. JDBC provides Java developers with an industry standard API for database-independent connectivity between java applications and a wide range of relational database management systems such as oracle. Informix, Microsoft SQL Server and Sybase. ‘The API provides a call level interface to the database. Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 4/24 J2EE Database Concepts 2016- 2018 Batch * Connect to a database ‘© Execute SQL statements to query your database + Generate query results + Perform updates, inserts and deletions + Execute stored procedures The following figure 2.1 shows the components of the JDBC model. In its simplest form, JDBC makes it possible to do these basic things: The Java application calls JDBC classes and interfaces to submit SQL statements and retrieve results. Figure 2.1 Components of the JDBC Model The JDBC API is implemented through the JDBC driver. The JDBC Driver is a set of classes that implement the JDBC interfaces to process JDBC calls and return result sets to a Java application. The database (or data store) stores the data retrieved by the application using the IDBC Driver JDBC OBJECTS ‘The main objects of the JDBC API include: ‘+ A Data Source object is used to establish connections. Although the Driver Manager can also be used to establish a connection, connecting through a Data Source object is the preferred method, Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 5/24 J2EE Database Concepts 2016- 2018 Batch ‘* A Connection object controls the connection to the database. An application can alter the behavior of a connection by invoking the methods associated with this object. An application uses the connection object to create statements = Statement, Prepared Statement, and Callable Statement objects are used for executing SQL statements. A Prepared Statement object is used when an application plans to reuse a statement multiple times. The application prepares the SQL it plans to use. Once prepared, the application can specify values for parameters in the prepared SQL statement. The statement can be executed multiple times with different parameter values specified for each execution. A Callable Statement is used to call stored procedures that return values. The Callable Statement has methods for retrieving the return values of the stored procedure A ResultSet object contains the results of a query. A ResultSet is returned to an application when a SQL query is executed by a statement object. The ResultSet object provides methods for iterating through the results of the query BENEFITS OF JDBC The benefits of using JDBC include the following: # A developer only needs to know one API to access any relational database «There is no need to rewrite code for different databases. + There is no need to know the database vendor's specific APIs * Itprovides a standard API and is vendor independent * Almost every database vendor has some sort of IDBC driver JDBC is part of the standard Java 2 platform 2.5 DRIVER TYPES IDBC technology-based drivers generally fit into one of four categories. In Figure 2.2 shows various driver implementation possibilities Prepared by Dr. Manju Priya, Department of CS, CA & IT, KAH Page 6/24 J2EE Database Concepts 2016- 2018 Batch ave Application mac ‘APL DSC Daver Manager APL TDBCNet |[ DBCODBC | [Driver] [Driver pewer |[ srdepaer || a |[ 8 | mac oDaCuml implemeateion pac Propsetry dtshaceancece potocale Misevare. Protocol Figure 2.2 Various driver implementation possibilities IDBC technology-based drivers generally fit into one of four categories. In Figure 2.2 shows various driver implementation possibilities JDBC Drivers Types Sun has defined four JDBC driver types. These are: Type 1: JDBC-ODBC Bridge Driver ‘The first type of JDBC driver is JDBC-ODBC Bridge which provides JDBC access to any ODBC complaint databases through ODBC drivers. Sun's JDBC-ODBC bridge is example of type | driver. Type 2: Native -API Partly - Java Driver Type 2 drivers are developed using native code libraries, which were originally designed for accessing the database through C/C++. Here a thin code of Java wrap around the native code and converts JDBC commands to DBMS-specific native calls. Type 3: JDBC-Net Pure Java Driver Type 3 drivers are three-tier solutions. This type of driver communicates to a middleware component which in turn connects to database and provide database connectivity. Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 7/24 J2EE Database Concepts 2016- 2018 Batch Type 4: Native-Protocol Pure Java Driver Type 4 drivers are entirely written in Java that communicates directly with vendor's database through socket connection. Here no translation or middleware layer, are required which improves performance tremendously JDBC-ODBC Bridge driver (Type 1 JDBC Driver) The Type 1 driver translates all JDBC calls into ODBC calls and sends them to the ODBC driver. ODBC is a generic API. The JDBC-ODBC Bridge driver is recommended only for experimental use or when no other alternative is available. In figure 2.3 Type 1 JDBC - ODBC Bridge Advantage The JDBC-ODBC Bridge allows access to almost any database, since the database's ODBC drivers are already available. Disadvantages 1. Since the Bridge driver is not written fully in Java, Typel drivers are not portable 2. A performance issue is seen as a IDBC call goes through the bridge to the ODBC driver, then to the database, and this applies even in the reverse process. They are the slowest of all driver types. ‘The jent system requires the ODBC Installation to use the driver and Not good for the Web, Figure 2.3 Type 1: JDBC-ODBC Bridge Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 8/24 J2EE Database Concepts 2016- 2018 Batch Native-APU/partly Java driver (Type 2 JDBC Driver) The distinctive characteristic of type 2 jdbe drivers is that Type 2 drivers convert JDBC calls into database-specifie calls i.e, this driver is specific to a particular database (shown in figure 2.4), Some distinctive characteristic of type 2 jdbe drivers are shown below. Example: Oracle will have oracle native api. Figure 2.4 Type 2: Native API/ Partly Java Driver Advantage The distinctive characteristic of type 2 jdbe drivers are that they are typically offer better performance than the JDBC-ODBC Bridge as the layers of communication (tiers) are less than that of Type I and also it uses Native api which is Database specific. Disadvantage 1, Native API must be installed in the Client System and hence type 2 drivers cannot be used for the Internet. 2. Like Type | drivers, it’s not written in Java Language which forms a portability issue 3. If we change the Database we have to change the native api as it is specific to a database 4, Mostly obsolete now 5. Usually not thread safe. Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 9/24 J2EE Database Concepts 2016- 2018 Batch All Java/Net-protocol driver (Type 3 JDBC Driver) Type 3 database requests are passed through the network to the middle-tier server. The middle~ tier then translates the request to the database (shown in fig 2.5). If the middle-tier server can in turn use Typel, Type 2 or Type 4 drivers. Figure 2.5 Type 3: All Javal Net-Protocol Driver Advantage 1. This driver is server-based, so there is no need for any vendor database library to be present on client machines 2. This driver is fully written in Java and hence Portable. It is suitable for the web There are many opportunities to optimize portability, performance, and scalability. 3. The net protocol can be designed to make the client JDBC driver very small and fast to load. 4, The type 3 driver typically provides support for features such as caching (connections, query results, and so on), load balancing, and advanced system administration such as logging and auditing, 5. This driver is very flexible allows access to multiple databases using one driver 6. They are the most efficient amongst all driver types. Disadvantage It requires another server application to install and maintain, Traversing the recordset may take longer, since the data comes through the backend server Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 10/24 J2EE Database Concepts 2016- 2018 Batch Native-protocoVall-Java driver (Type 4 JDBC Driver) The Type 4 uses java networking libraries to communicate directly with the database server (shown in fig 2.6) Figure 2.6 Type 4: Native-protocoVall-Java driver Advantage 1, The major benefit of using a type 4 jdbe drivers are that they are completely written in Java to achieve platform independence and eliminate deployment administration issues. It is most suitable for the web. Number of translation layers is very less i.e. type 4 IDBC drivers don't have to translate database requests to ODBC or a native connectivity interface or to pass the request on to another server, performance is typically quite good 3. You don’t need to install special software on the client or server. Further, these drivers can be downloaded dynamically. Disadvantage With type 4 drivers, the user needs a different driver for each database, 2.6 JDBC PACKAGE The purpose of the JDBC package is to provide vendor-neutral access to relational databases. The implementation differences of the various databases used are abstracted from the user through the use of the JDBC API. Though the specification does not indicate that the API is to be Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 11/24 J2EE Database Concepts 2016- 2018 Batch used solely for relational databases, historically it has been used primarily for relational database a S. ‘The developers of the JDBC API specification have tried to keep the API as simple as possible so that it can be a foundation upon which other APIs are built. For instance, the connector API can be implemented on top of an existing JDBC API using appropriate resource adapters. JDBC is composed of a number of interfaces, These interfaces are implemented by driver developers. ‘The API is implemented by either a vendor or a third party to create a JDBC driver. The Type 4 JDBC driver is considered the best driver to use for two reasons. One reason is that since the driver has been written completely in Java, it is extremely portable. Another reason is that the driver is not required to map JDBC calls to corresponding native CLI calls. This avoids the overhead of mapping logic required by the Type 1 or Type 2 driver, or the overhead of communicating with middleware required by the Type 3 driver. Such improvements in efficiency should allow the driver to execute faster than the other types of JDBC drivers. 2.6.1 JDBC 2.0 API ‘The JDBC 2.0 API includes the complete JDBC API, which includes both core and Optional Package API, and provides industrial-strength database computing capabilities. It is not, however, limited to SQL databases; the DBC 2.0 API makes it possible to access data from virtually any data source with a tabular format The JDBC 2.0 API includes two packages: ‘+ java.sql package-the JDBC 2.0 core API JDBC API included in the JDKTM 1.1 release (previously called JDBC 1.2). This API is compatible with any driver that uses JDBC technology. © JDBC API included in the Java 2 SDK, Standard Edition, version 1.2 (called the JDBC 2.0 core API). This API includes the JDBC 1.2 API and adds many new features, Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 12/24 J2EE Database Concepts 2016- 2018 Batch + javax.sql package~the JDBC 2.0 Optional Package API. This package extends the functionality of the JDBC API from a client-side API to a server-side API, and it is an essential part of Java2 SDK, Enterprise Edition technology. Being an Optional Package, it is not included in the Java 2 Platform SDK, Standard Edition, version 1.2, but it is readily available from various sources. Information about the JDBC 2.0 Optional Package API is available from the JDBC web page. The javax.sql package may also be downloaded from this web site. Driver vendors may include the javax.sql package with their prod © The Java 2 SDK, Enterprise Edition, includes many Optional Package APIs, including the JDBC 2.0 Optional Package. 2.6.2 The java.sql Package ‘The java.sql package contains the entire JDBC API that sends SQL (Structured Query ecuting those SQL. Language) statements to relational databases and retrieves the results of e statements, ‘The Driver interface represents a specific JDBC implementation for a particular database system, Connection represents a connection to a database, The Statement, PreparedStatement, and CallableStatement interfaces support the execution of various kinds of SQL statements, ResultSet is a set of results returned by the database in response to a SQL query. The ResultSetMetaData interface provides metadata about a result set, while DatabaseMetaData provides metadata about the database as a whole. ‘The java.sql package contains API for the following: ‘+ Making a connection with a data source © DriverManager class © Driver interface © DriverPropertyInfo class © Connection interface Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 13/24 J2EE Database Concepts 2016- 2018 Batch ‘+ Custom mapping an SQL user-defined type to a class in the Java programming language SQLData interface SQLInput interface © SQLOutput interface ‘+ Providing information about the database and the columns of a ResultSet object © DatabaseMetaData interface oo ResultSetMetaData interface + Throwing exceptions © SQLException thrown by most methods when there is a problem accessing data and by some methods for other reasons © SQLWarning thrown to indicate a warning © DataTruncation thrown to indicate that data may have been truncated BatchUpdateException thrown to indicate that not all commands in a batch update executed successfully + Providing security © SQLPermission interface 2.7 JDBC PROCESS Steps involved in JDBC Process: 1, Load the driver 2. Define the Connection URL, 3, Establish the Connection 4, Create a Statement object 5, Execute a query 6, Process the results, 7. Close the connection Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 14/24 J2EE Database Concepts 2016- 2018 Batch 1. Load the driver uy { Class. forName("connect. microsoft. MicrosoftDriver"); Class. forName( “oracle. jdbc. driver. OracleDriver } catch { ClassNotFoundException enfe) { System.out.println("Error loading driver: " enfe); } 2. Define the Connection URL String host = "dbhost.yourcompany.com";, String dbName = "someName"; int port = 1234; String oracleURL = "jdbe:oracle:thin:@" + host +"" + port +"" dbName; String sybaseURL = "jdbe:sybase:Tds:" + host + not port + "2SERVICENAME=" + dbName; 3. Establish the Connection Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 15/24 J2EE Database Concepts 2016- 2018 Batch String username = "jay_debesee"; String password = "secret"; Connection connection =_ DriverManager. getConnection(oracleURL,username, password); + Optionally, look up information about the database DatabaseMetaData dbMetaData = connection.ge(MetaData(); String productName = dbMetaData.getDatabaseProductName(); System.out println("Database: " + productName); String productVersion = dbMetaData.getDatabaseProductVersion(), System.out.printin("Version: " + produetVersion); 4, Create a Statement Statement statement = connection.createStatement(); 5. Execute a Query String query = "SELECT coll, col2, col3 FROM sometable"; ResultSet resultSet = statement executeQuery(query); — To modify the database, use executeUpdate, supplying a string that uses UPDATE, INSERT, or DELETE, — Use setQueryTimeout to specify a maximum delay to wait for results 6. Process the Result while(resultSet.next()) { System.out printIn(resultSet. getString(1) + Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 16/24 J2EE Database Concepts 2016- 2018 Batch resultSet, getString(2) + resultSet.getString(3)); First column has index 1, not 0 — ResultSet provides various getXrx methods that take a colu index or column name and returns the data — You can also access result meta data (column names, ete.) 7. Close the Conneetion connection.close(); ~ Since opening a connection is expensive, postpone this step if additional database operations are expected 2.8 STATEMENT OBJECTS Through the Statement object, SQL statements are sent to the database. Three types of statement objects are available: + Statement — For executing a simple SQL statement + PreparedStatement — For executing a precompiled SQL statement passing in parameters + CallableStatement —For executing a database stored procedure Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 17/24 J2EE Database Concepts 2016- 2018 Batch ‘Statement Methods * executeQuery — Executes the SQL query and returns the data in a table (ResultSet) ~The resulting table may be empty but never null ResultSet results = statement.executeQuery("SELECT a, b FROM_ table"); + executeUpdate — Used to execute for INSERT, UPDATE, or DELET) SQL statements ~The return is the number of rows that were affected in the database — Supports Data Definition Language (DDL) statements CREATE TABLE, DROP TABLE and ALTER TABLE int rows ~ statement.executeUpdate("DELETE FROM EMPLOYEES" + _ "WHERE STATUS=0"); © execute — Generic method for executing stored procedures and prepared statements ~ Rarely used (for multiple return result sets) — The statement execution may or may not return @ ResultSet (use tatement. getResultSet). Ifthe return value is true, two or more result sets were produced + getMaxRows/setMaxRows Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHI Page 18/24

You might also like