Servlet 5.1 JDBC 5.2 JDBC

Similar documents
( A ) 8. If the address of an array is stored in $value, how do you get the values of this array? (B) \$value (C) &$value (D) $$value

SWE642 Oct. 22, 2003

2. Follow the installation directions and install the server on ccc. 3. We will call the root of your installation as $TOMCAT_DIR

SQream Connector JDBC SQream Technologies Version 2.9.3

3. The pool should be added now. You can start Weblogic server and see if there s any error message.

This lecture. Databases - JDBC I. Application Programs. Database Access End Users

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

Lab # 9. Java to Database Connection

ServletConfig Interface

DataBase Lab JAVA-DATABASE CONNECTION. Eng. Haneen El-masry

Accessing databases in Java using JDBC

ERwin and JDBC. Mar. 6, 2007 Myoung Ho Kim

CreateServlet.java

CREATE A SERVLET PROGRAM TO DISPLAY THE STUDENTS MARKS. To create a servlet program to display the students marks

Programming in Java

CSCI/CMPE Object-Oriented Programming in Java JDBC. Dongchul Kim. Department of Computer Science University of Texas Rio Grande Valley

JAVA SERVLET. Server-side Programming ADVANCED FEATURES

Working with Databases and Java

Discuss setting up JDBC connectivity. Demonstrate a JDBC program Discuss and demonstrate methods associated with JDBC connectivity

Develop an Enterprise Java Bean for Banking Operations

SQL and Java. Database Systems Lecture 20 Natasha Alechina

Complimentary material for the book Software Engineering in the Agile World

Advanced Internet Technology Lab # 4 Servlets

DB I. 1 Dr. Ahmed ElShafee, Java course

COP4540 TUTORIAL PROFESSOR: DR SHU-CHING CHEN TA: H S IN-YU HA

JAVA SERVLET. Server-side Programming INTRODUCTION

Java Database Connectivity

JDBC Architecture. JDBC API: This provides the application-to- JDBC Manager connection.

Author - Ashfaque Ahmed

Web based Applications, Tomcat and Servlets - Lab 3 -

Servlet. 1.1 Web. 1.2 Servlet. HTML CGI Common Gateway Interface Web CGI CGI. Java Applet JavaScript Web. Java CGI Servlet. Java. Apache Tomcat Jetty

Copyright 2005, by Object Computing, Inc. (OCI). All rights reserved. Database to Web

Server-side Web Programming

Java Database Connectivity (JDBC) 25.1 What is JDBC?

Scheme G Sample Question Paper Unit Test 2

Cyrus Shahabi Computer Science Department University of Southern California C. Shahabi

Application Programming for Relational Databases

JDBC, Transactions. Niklas Fors JDBC 1 / 38

Database Programming Overview. COSC 304 Introduction to Database Systems. Database Programming. JDBC Interfaces. JDBC Overview

Getting started with Winstone. Minimal servlet container

To create a view for students, staffs and courses in your departments using servlet/jsp.

Running SQL in Java and PHP

Database connectivity (II)

Database Application Programs PL/SQL, Java and the Web

e-pg Pathshala Subject: Computer Science Paper: Web Technology Module: JDBC INTRODUCTION Module No: CS/WT/26 Quadrant 2 e-text

1. PhP Project. Create a new PhP Project as shown below and click next

Web Applications and Database Connectivity using JDBC (Part II)

Three-Tier Architecture

Visit for more.

PERSİSTENCE OBJECT RELATİON MAPPİNG

CSE 135. Three-Tier Architecture. Applications Utilizing Databases. Browser. App. Server. Database. Server

Types of Databases. Types of Databases. Types of Databases. Databases and Web. Databases and Web. Relational databases may also have indexes

Chettinad College of Engineering and Technology CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE AND TECHNOLOGY

Java Enterprise Edition. Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1

SQL in a Server Environment

Enterprise Java Unit 1- Chapter 6 Prof. Sujata Rizal

ICOM 5016 Database Systems. Database Users. User Interfaces and Tools. Chapter 8: Application Design and Development.

JDBC Drivers Type. JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server.

AJP. CHAPTER 5: SERVLET -20 marks

Backend. (Very) Simple server examples

INTRODUCTION TO SERVLETS AND WEB CONTAINERS. Actions in Accord with All the Laws of Nature

Database Access with JDBC. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Databases 2012 Embedded SQL

Servlets1. What are Servlets? Where are they? Their job. Servlet container. Only Http?

a. Jdbc:ids://localhost:12/conn?dsn=dbsysdsn 21. What is the Type IV Driver URL? a. 22.

CHAPTER 2 JDBC FUNDAMENTALS

Database Programming. Week 9. *Some of the slides in this lecture are created by Prof. Ian Horrocks from University of Oxford

Pieter van den Hombergh. March 25, 2018

Outline. Lecture 10: Database Connectivity -JDBC. Java Persistence. Persistence via Database

3) execute() Usage: when you cannot determine whether SQL is an update or query return true if row is returned, use getresultset() to get the

C:/Users/zzaier/Documents/NetBeansProjects/WebApplication4/src/java/mainpackage/MainClass.java

Part I: Stored Procedures. Introduction to SQL Programming Techniques. CSC 375, Fall 2017

Running SQL in Java and PHP

Allenhouse Institute of Technology (UPTU Code : 505) OOT Notes By Hammad Lari for B.Tech CSE V th Sem

DEZVOLTAREA APLICATIILOR WEB CURS 7. Lect. Univ. Dr. Mihai Stancu

Enterprise Systems. Lecture 02: JDBC. Behzad BORDBAR

Unit-4: Servlet Sessions:

A.1 JSP A.2 JSP JSP JSP. MyDate.jsp page contenttype="text/html; charset=windows-31j" import="java.util.calendar" %>

The Design of JDBC The Structured Query Language Basic JDBC Programming Concepts Query Execution Scrollable and Updatable Result Sets

Content Services for JDBC Driver User Guide

Introduction. This course Software Architecture with Java will discuss the following topics:

Chapter 16: Databases

JDBC Java Database Connectivity is a Java feature that lets you connect

Embedded SQL. csc343, Introduction to Databases Diane Horton with examples from Ullman and Widom Fall 2014

Programming on the Web(CSC309F) Tutorial 9: JavaServlets && JDBC TA:Wael Abouelsaadat

Introduction to Databases

Université Antonine - Baabda

Introduction. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003

JDBC [Java DataBase Connectivity]

JDBC Guide. RDM Server 8.2

access to a JCA connection in WebSphere Application Server

13 Creation and Manipulation of Tables and Databases

Calling SQL from a host language (Java and Python) Kathleen Durant CS 3200

CIS 3952 [Part 2] Java Servlets and JSP tutorial

Servlet for Json or CSV (or XML) A servlet serving either Json or CSV (or XML) based on GET parameter - This version uses org.json

Unit 2 JDBC Programming

More Database Programming. CS157A Chris Pollett Nov. 2, 2005.

Servlet. Web Server. Servlets are modules of Java code that run in web server. Internet Explorer. Servlet. Fire Fox. Servlet.

INTERNET PROGRAMMING TEST-3 SCHEME OF EVALUATION 1.A 3 LIFE CYCLE METHODS - 3M 1.B HTML FORM CREATION - 2 M

UNIT-3 Java Database Client/Server

Transcription:

5 Servlet Java 5.1 JDBC JDBC Java DataBase Connectivity Java API JDBC Java Oracle, PostgreSQL, MySQL Java JDBC Servlet OpenOffice.org ver. 2.0 HSQLDB HSQLDB 100% Java HSQLDB SQL 5.2 JDBC Java 1. JDBC 2. 3. SQL 4. SQL 5. DBSelect.java DBSelect.java customer "SELECT * FROM customer" SQL HTML java.sql.* import JDBC - 5 p.1

DBSelect.java import java.io.*; import java.sql.*; import javax.servlet.http.*; public class DBSelect extends HttpServlet { @Override public void doget(httpservletrequest request, HttpServletResponse response) throws IOException { Connection conn = null; response.setcontenttype("text/html; charset=windows-31j"); PrintWriter out = response.getwriter(); out.println("<html><head></head><body>"); out.println("<table border= true >"); out.println("<tr><th>id</th><th>first</th><th>last</th>" +"<th>street</th><th>city</th></tr>"); Class.forName("org.hsqldb.jdbcDriver"); // JDBC String url = "jdbc:hsqldb:hsql://localhost"; // HSQLDB URL String user = "sa", password=""; // HSQLDB conn = DriverManager.getConnection(url, user, password); // Statement stmt = conn.createstatement(); ResultSet rs = stmt.executequery("select * FROM customer"); // SQL while (rs.next()) { out.print("<tr>"); out.print("<td>"+rs.getstring("id")+"</td>"); out.print("<td>"+rs.getstring("firstname") + "</td>"); out.print("<td>"+rs.getstring("lastname") + "</td>"); out.print("<td>"+rs.getstring("street") + "</td>"); out.print("<td>"+rs.getstring("city") + "</td>"); out.print("</tr>"); catch (ClassNotFoundException e) { out.println(" "); catch (SQLException e) { out.println(" "); finally { if (conn!= null) { conn.close(); /* */ catch (SQLException e) { out.println("</table>"); out.println("</body></html>"); out.close(); - 5 p.2

5.2.1 JDBC JDBC JDBC Class.forName HSQLDB "org.hsqldb.jdbcdriver" 1 Class.forName("org.hsqldb.jdbcDriver"); JDBC class ClassNotFoundException ClassNotFoundException catch 5.2.2 DriverManager.getConnection 1 URL JDBC Servlet HSQLDB URL "jdbc:hsqldb:hsql://localhost" 2 3 HSQLDB "sa" "" java.sql.connection Connection : JDBC URL 5.2.3 SQL SQL java.sql.statement Statement Connection createstatement Statement executequery SQL SELECT SQL Java Java executequery java.sql.resultset SQLException catch 1 JDBC - 5 p.3

ResultSet ResultSet next next next false ResultSet getstring String HSQLDB customer id, firstname, lastname, street, city 5 ResultSet getstring getint getter getter ( ) ( ) java.sql.resultset ((J2SEAPI)/java/sql/ResultSet.html) 5.2.1 java.sql.preparedstatement 5.2.4 DBSelect.java try finally conn.close() 5.3 customer DBUpdate.html <html><head></head> <body> <form action= servlet/dbupdate method= POST > <br> <table border> <tr><th> </th> <th> </th></tr> <tr><td>id</td> <td><input type= text size= 5 name= id ></td></tr> <tr><td>street</td><td><input type= text size= 32 name= street ></td></tr> <tr><td>city</td> <td><input type= text size= 32 name= city ></td></tr> </table> <input type= submit value= > </form> </body> </html> executequery executeupdate SQL UPDATE INSERT DELETE executeupdate - 5 p.4

DBUpdate.java import java.io.*; import java.sql.*; import javax.servlet.http.*; public class DBUpdate extends HttpServlet { @Override public void dopost(httpservletrequest request, HttpServletResponse response) throws IOException { Connection conn = null; response.setcontenttype("text/html; charset=windows-31j"); PrintWriter out = response.getwriter(); out.println("<html><head></head><body>"); String id = request.getparameter("id"); String street = request.getparameter("street"); String city = request.getparameter("city"); String user = "sa", password=""; Class.forName("org.hsqldb.jdbcDriver"); String url = "jdbc:hsqldb:hsql://localhost"; conn = DriverManager.getConnection(url, user, password); Statement stmt = conn.createstatement(); stmt.executeupdate("update customer SET street = "+street +", city = "+city+" WHERE id = "+id); out.println(" <br>"); out.println("id="+id+", street= "+street+", city= "+city+" "); catch (ClassNotFoundException e) { out.println(" "); catch (SQLException e) { out.println(" "); finally { if (conn!= null) { conn.close(); catch (SQLException e) { out.println("</body></html>"); out.close(); - 5 p.5

executeupdate SQL ( DBUpdate.java ) DBSelect.java ( ) 5.3.1 X price 15 10% HSQLDB product price product X 5.3.2 HSQLDB customer HTML : JDBC, Class.forName, DriverManager.getConnection, Connection, createstatement, Statement, executequery, executeupdate, ResultSet, next, getstring, - 5 p.6