DataBases and SQL INFSY 547 Spring 2007. Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:

Slides:



Advertisements
Similar presentations
Servlets, JSP and JavaBeans Joshua Scotton.  Getting Started  Servlets  JSP  JavaBeans  MVC  Conclusion.
Advertisements

 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
J.Sant Servlets Joseph Sant Sheridan Institute of Technology.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
Servlets and JDBC. Servlets A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password:
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
An introduction to Java Servlet Programming
JSP Java Server Pages Reference:
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
Core Servlets Chapter 3 Link for Core Servlets code: om/archive/ om/archive/
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.
1 CS6320 – Servlet Structure and Lifecycle L. Grewe.
27-Jun-15 Directories and DDs. 2 Web apps A web application is basically a web site that: “Knows who you are”--it doesn’t just give you static pages,
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password:
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
Server Side Programming Web Information Systems 2012.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
Java Servlets and JSP.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 30 - Servlets: Bonus for Java Developers Outline 30.1 Introduction 30.2 Servlet Overview and.
CSC 2720 Building Web Applications
Java Servlets and Java Server Pages Carol Wolf Computer Science.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
SKT-SSU IT Training Center Servlet and JSP. Chapter Three: Servlet Basics.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
Java Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface Servlet and the Servlet Life Cycle HttpServlet Class.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Java Servlets & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
S ERVLETS Hits Counter 21-Nov-15. S ERVLETS - H ITS C OUNTER Many times you would be interested in knowing total number of hits on a particular page of.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
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:
 2002 Prentice Hall. All rights reserved. 9.8 Multi-Tier Applications: Using JDBC from a Servlet Three-tier distributed applications –User interface –Business.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Configuration Web Server Tomcat - Install JDK Install Tom cat Configure Tom cat for running Servlet C:\Program Files\Apache Software Foundation\Tomcat.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
ClaRA web services V. Gyurjyan Clas12 Software Meeting
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
J2EE/Java EE Apache Tomcat v9 IBM Websphere v8 Redhat JBoss EAP v6 Oracle Weblogic v12 Fusion Web Tier ServletsJSPJSF Business Tier JMXJMSEJB.
S ERVLETS Form Data 19-Mar-16. F ORM P ROCESSING You must have come across many situations when you need to pass some information from your browser to.
Java Database Connectivity JDBC. Open Database Connectivity developed by Microsoft to provide interaction with databases using SQL. Use the JDBC-ODBC.
Servlets Outline 1 Introduction 2 Servlet Overview and Architecture 2.1 Interface Servlet and the Servlet Life Cycle 2.2 HttpServlet Class 2.3 HttpServletRequest.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Servlets Outline Introduction Servlet Overview and Architecture Interface Servlet and the Servlet Life Cycle HttpServlet Class HttpServletRequest.
Servlet Fudamentals.
JDBC & Servlet CSE 4504/6504 Lab.
Servlets Hits Counter 20-Jul-18.
V. Gyurjyan Clas12 Software Meeting
Chapter 24: Servlets Outline Introduction Servlet Overview and Architecture Interface Servlet and the Servlet Life Cycle
COP 4610L: Applications in the Enterprise Spring 2005
COP 4610L: Applications in the Enterprise Spring 2005
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Java Servlets Servlet Overview Servlets and HTML Forms Servlet Basics
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Basic servlet structure
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

DataBases and SQL INFSY 547 Spring 2007

Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19: Review Form ideas, Team Meetings and presentation guidelines April 26: Project Due Date Develop presentations May 3: Final Presentation and Party

Servlet Processing  Process a database (similar to an.xml file)  Output an.html file  Interact with Oracle via a servlet

In SQL Plus

Lab 10: Start with Eclipse  Create a project in Eclipse – (Infsy547OracleCustomerLab.java)  External.jar files classes12.jar servlet-api.jar

Lab 10: Start with Eclipse  Create a package – infsy547oraclecustomerlab  Create a class – by the same name as the project  Add import statements import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*;

Servlet Assuming Names Table public class Infsy547OracleCustomer extends HttpServlet { private Connection connection; private PreparedStatement insertRecord; private int acctNumber; private PrintWriter out; Names acctNumber* nameaddresscitystate

public void init( ServletConfig config ) throws ServletException { }

private void getConnected () { try { Class.forName( "oracle.jdbc.driver.OracleDriver" ); connection = DriverManager.getConnection “ ",“ "); // PreparedStatement to add a customer record to names table insertRecord = connection.prepareStatement ( "INSERT INTO names (name, address, city, state, accountnumber) " + "VALUES(?, ?, ?, ?, ?)"); } catch(ClassNotFoundException cnf) { System.err.println(cnf.getMessage()); cnf.printStackTrace(); } catch (SQLException sqlex) { System.err.println(sqlex.getMessage()); sqlex.printStackTrace(); } } Loads the driver for Oracle

protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { // set up response to client response.setContentType( "text/html" ); out = response.getWriter(); // start XHTML document out.println( " " ); out.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD " + "XHTML 1.0 Strict//EN\" \" + "/TR/xhtml1/DTD/xhtml1-strict.dtd\">" ); out.println(" " ); // head section of document out.println( " " ); acctNumber = Integer.parseInt(request.getParameter("accountNumber")); name = request.getParameter("Name"); out.println( " Thank you! " ); out.println( " " ); out.println( " Thank you for adding your record." ); out.println( " " ); out.close(); }

public void insertRecord () { try { // update total for current survey response insertRecord.setString( 1, name ); insertRecord.setString( 2, address ); insertRecord.setInt( 5, acctNumber); insertRecord.executeUpdate(); } catch ( SQLException sqlException ) { sqlException.printStackTrace(); out.println( " Error " ); out.println( " " ); out.println( " Database error occurred. " ); out.println( "Try again later. " ); out.close(); } Note: Will not complete the html on previous page if this occurs.

@Override public void destroy() { // attempt to close statements and database connection try { insertRecord.close(); connection.close(); } catch( SQLException sqlException ) { sqlException.printStackTrace(); } } // end of destroy method

● Exceptions represent error conditions ● Exceptions isolate the code that deals with error situations ● Throwing: the act of detecting an abnormal condition  Searches for a handler  catches the exception ● Try Block: Encloses one or more java statements Exception Terminology

HTML Insert Customer Account Number

Complete Place files appropriately in TomCat structure Add to web.xml Start TomCat Start you servlet

.java file from this lab –uploaded to the DataBase Connectivity Drop Box –In ANGEL under the Lessons Tab.html file –Upload into HTML Drop Box