Web Application Deployment & JDBC CSC 667, Spring 2004 Dr. Ilmi Yoon.

Slides:



Advertisements
Similar presentations
 2003 Prentice Hall, Inc. All rights reserved. Chapter 22 – Database: SQL, MySQL, DBI and ADO.NET Outline 22.1 Introduction 22.2 Relational Database Model.
Advertisements

Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
Fundamentals, Design, and Implementation, 9/e Chapter 14 JDBC, Java Server Pages, and MySQL.
1 Build a Web Application on J2EE. 2 J2EE Scenario Client – Web Server – EIS Resources Client – Web Server – EIS Resources Client – Application Server.
2/16/2004 Dynamic Content February 16, /16/2004 Assignments Due – Message of the Day Part 1 Due – Reading and Warmup Work on Message of the Day.
Web Application Deployment & JDBC CSC 667, Spring 2007 Dr. Ilmi Yoon.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Exercise SELECT authorID, lastName FROM authors AuthorID FirstName
Java Servlets and JSP.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
CSCI 6962: Server-side Design and Programming
Java Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
ASP.NET Programming with C# and SQL Server First Edition
CSE470 Software Engineering Fall Database Access through Java.
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
Database Programming in Java Corresponds with Chapter 32, 33.
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
 2003 Prentice Hall, Inc. All rights reserved. 1 Java Database Connectivity with JDBC TM.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES LECTURE 5_1 George Koutsogiannakis/ Summer
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
Active Server Pages ASP is Microsoft’s server-side script engine for dynamically-generated web pages. Most common language used is VBScript. If you use.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 MySQL and JDBC.
Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Database: SQL and MySQL
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
1 Databases November 15, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg. Published.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
Java Servlets & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2.
 2005 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
DataBases and SQL INFSY 547 Spring Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 22 - SQL, MySQL, DBI and ADO Outline 22.1 Introduction 22.2 Relational Database Model 22.3 Relational.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Web Programming Assistant Professor Xiaozhong Liu
Database Processing with JSP ISYS 350. Database Applications Applications Database Server Queries/Updates Results.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
ORDER BY Clause The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of.
Database Programming in Java
Java Servlets By: Tejashri Udavant..
 2012 Pearson Education, Inc. All rights reserved.
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Accessing Databases with JDBC
JDBC.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 8 Working with Databases and MySQL
Chapter 22 - SQL, MySQL, DBI and ADO
Presentation transcript:

Web Application Deployment & JDBC CSC 667, Spring 2004 Dr. Ilmi Yoon

Web Application With the release of the Java Servlet Specification 2.2 Web Application is a collection of servlets, html pages, classes, and other resources that can be bundled and run on multiple containers from multiple vendors Each web application has one and only one ServletContext 3/15/tomcat.htmlhttp:// 3/15/tomcat.html 4/19/tomcat.htmlhttp:// 4/19/tomcat.html

Deployment Deployment descriptor (web.xml) Web applications can be changed without stopping the server With a standardized deployment comes standardized tools Check 24/667_files/frame.htm for tips for Ant, TogetherSoft, Tomcat install & deployment 24/667_files/frame.htm

Table 1. The Web Application Directory Structure DirectoryContains /onjava This is the root directory of the web application. All JSP and XHTML files are stored here. /onjava/WEB-INF This directory contains all resources related to the application that are not in the document root of the application. This is where your web application deployment descriptor is located. Note that the WEB-INF directory is not part of the public document. No files contained in this directory can be served directly to a client. /onjava/WEB-INF/classes This directory is where servlet and utility classes are located. /onjava/WEB-INF/lib This directory contains Java Archive files that the web application depends upon. For example, this is where you would place a JAR file that contained a JDBC driver.

Installation & Setup Update CLASSPATH –Identify the Classes (jsp.jar, jspengine.jar, servlet.jar, jasper.jar) to the java Compiler –Unix CLASSPATH=${TOMCAT_HOME}/webserver.jar CLASSPATH=${CLASSPATH}:${TOMCAT_HOME}/webserver.jar CLASSPATH=${CLASSPATH}:${TOMCAT_HOME}/lib/servlet/jar CLASSPATH=${CLASSPATH}:${TOMCAT_HOME}/lib/jsper.jar CLASSPATH=${CLASSPATH}:${TOMCAT_HOME}/examples/WEB- INF/classes –Windows set CLASSPATH=.;dir\servlet.jar;dir\jspengine.jar

Installation & Setup Compile and Install your servlets –Tomcat install_dir/webpages/WEB-INF/classes install_dir/classes install_dir/lib (non frequently changing classes) install_dir/webapps/ROOT/WEB- INF/classes (3.1) Invoking the servlets – ame use /servlet/ regardless the actual directory name –Register servlet

Calling Servlets From a Browser The URL for a servlet has the following general form, where servlet-name corresponds to the name you have given your servlet: Servlet URLs can contain queries, such as for HTTP GET requests. For example, if the servlet's name is bookdetails; the URL for the servlet to GET and display all the information about the bookstore's featured book is: 203

Web.xml – under WEB_INF The OnJava App 30 TestServlet com.onjava.TestServlet 1 name value The OnJava App 30 TestServlet com.onjava.TestServlet 1 name value

Packing the Web Application Web ARchive file (WAR) Command : jar cvf onjava.war. Now you can deploy your web application by simply distributing this file

Table 5. The Tomcat Directory Structure /bin /conf This directory contains the main configuration files for Tomcat. The two most important are the server.xml and the global web.xml. /serverThis directory contains the Tomcat Java Archive files. /libThis directory contains Java Archive files that Tomcat is dependent upon. /logsThis directory contains Tomcat's log files. /srcThis directory contains the source code used by the Tomcat server. Once Tomcat is released, it will probably contain interfaces and abstract classes only. /webappsAll web applications are deployed in this directory; it contains the WAR file. /work This is the directory in which Tomcat will place all servlets that are generated from JSPs. If you want to see exactly how a particular JSP is interpreted, look in this directory.

Steps Involved in Deploying a Web Application to Tomcat 1.Copy your WAR file to the TOMCAT_HOME/webapps directory. 2.Add a new Context entry to the TOMCAT_HOME/conf/server.xml file, setting the values for the path and docBase to the name of your web application. 3. If you look at the TOMCAT_HOME/webapps directory, you will see a new directory matching the name of your WAR file

JDBC Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational database –Structured Query Language JDBC –Java Database Connectivity –JDBC driver

Relational-Database Model Relational database –Table –Record –Field, column –Primary key Unique data SQL statement –Query –Record sets

Manipulating Databases with JDBC Connect to a database Query the database Display the results of the query

Connecting to and Querying a JDBC Data Source DisplayAuthors –Retrieves the entire authors table –Displays the data in a JTextArea

public class SQLGatewayServlet extends HttpServlet{ private Connection connection; public void init() throws ServletException{ try{ Class.forName("org.gjt.mm.mysql.Driver"); String dbURL = "jdbc:mysql://localhost/murach"; String username = "root"; String password = ""; connection = DriverManager.getConnection( dbURL, username, password); } Create Connection at Init()

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ String sqlStatement = request.getParameter("sqlStatement"); String message = ""; try{ Statement statement = connection.createStatement(); sqlStatement = sqlStatement.trim(); String sqlType = sqlStatement.substring(0, 6); if (sqlType.equalsIgnoreCase("select")){ ResultSet resultSet = statement.executeQuery(sqlStatement); // create a string that contains a HTML-formatted result set message = SQLUtil.getHtmlRows(resultSet); } else { int i = statement.executeUpdate(sqlStatement); if (i == 0) // this is a DDL statement message = "The statement executed successfully."; else // this is an INSERT, UPDATE, or DELETE statement message = "The statement executed successfully. " + i + " row(s) affected."; } statement.close(); } From JDBC Example at course web page

public void init() throws ServletException{ connectionPool = MurachPool.getInstance(); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ Connection connection = connectionPool.getConnection(); String firstName = request.getParameter("firstName"); String lastName = request.getParameter("lastName"); String Address = request.getParameter(" Address"); User user = new User(firstName, lastName, Address); HttpSession session = request.getSession(); session.setAttribute("user", user); String message = "";

Processing Multiple ResultSets or Update Counts Execute the SQL statements Identify the result type –ResultSet s –Update counts Obtain result –getResultSet –getUpdateCount

JDBC 2.0 Optional Package javax.sql Package javax.sql –Included with Java 2 Enterprise Edition Interfaces in package javax.sql –DataSource –ConnectionPoolDataSource –PooledConnection –RowSet

Connection Pooling Database connection –Overhead in both time and resources Connection pools –Maintain may database connections –Shared between the application clients

Relational DB and SQL statements This section is self-study section

Relational-Database Model Relational-database structure of an Employee table.

Relational Database Overview: The books Database Sample books database –Four tables Authors, publishers, authorISBN and titles –Relationships among the tables

Relational Database Overview: The books Database

Relational Database Overview: The books Database (Cont.)

Relational Database Overview: The books Database

Relational Database Overview: The books Database (Cont.)

Fig. 8.11Table relationships in books.

Structured Query Language (SQL) SQL overview SQL keywords

Basic SELECT Query Simplest format of a SELECT query –SELECT * FROM tableName SELECT * FROM authors Select specific fields from a table –SELECT authorID, lastName FROM authors

WHERE Clause specify the selection criteria –SELECT fieldName1, fieldName2, … FROM tableName WHERE criteria SELECT title, editionNumber, copyright FROM titles WHERE copyright > 1999 WHERE clause condition operators –, =, =, <> –LIKE wildcard characters % and _

WHERE Clause (Cont.) SELECT authorID, firstName, lastName FROM authors WHERE lastName LIKE ‘D%’

WHERE Clause (Cont.) SELECT authorID, firstName, lastName FROM authors WHERE lastName LIKE ‘_i%’

ORDER BY Clause Optional ORDER BY clause –SELECT fieldName1, fieldName2, … FROM tableName ORDER BY field ASC –SELECT fieldName1, fieldName2, … FROM tableName ORDER BY field DESC ORDER BY multiple fields –ORDER BY field1 sortingOrder, field2 sortingOrder, … Combine the WHERE and ORDER BY clauses

ORDER BY Clause (Cont.) SELECT authorID, firstName, lastName FROM authors ORDER BY lastName ASC

ORDER BY Clause (Cont.) SELECT authorID, firstName, lastName FROM authors ORDER BY lastName DESC

ORDER BY Clause (Cont.) SELECT authorID, firstName, lastName FROM authors ORDER BY lastName, firstName

ORDER BY Clause (Cont.) SELECT isbn, title, editionNumber, copyright, price FROM titles WHERE title LIKE ‘%How to Program’ ORDER BY title ASC

Merging Data from Multiple Tables: Joining Join the tables –Merge data from multiple tables into a single view –SELECT fieldName1, fieldName2, … FROM table1, table2 WHERE table1.fieldName = table2.fieldName –SELECT firstName, lastName, isbn FROM authors, authorISBN WHERE authors.authorID = authorISBN.authorID ORDER BY lastName, firstName

Merging Data from Multiple Tables: Joining (Cont.)

INSERT INTO Statement Insert a new record into a table –INSERT INTO tableName ( fieldName1, …, fieldNameN ) VALUES ( value1, …, valueN ) INSERT INTO authors ( firstName, lastName ) VALUES ( ‘Sue’, ‘Smith’ )

UPDATE Statement Modify data in a table –UPDATE tableName SET fieldName1 = value1, …, fieldNameN = valueN WHERE criteria UPDATE authors SET lastName = ‘Jones’ WHERE lastName = ‘Smith’ AND firstName = ‘Sue’

DELETE FROM Statement Remove data from a table –DELETE FROM tableName WHERE criteria DELETE FROM authors WHERE lastName = ‘Jones’ AND firstName = ‘Sue’