1 Download current version of Tomcat from: g/tomcat/ g/tomcat/ Install it in: C:\Program Files\Apache.

Slides:



Advertisements
Similar presentations
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Advertisements

19 augustus 2003augustus 2003 JSP-2. BICT 2JDBC BICT 3Install MySQL Download MySQL daemon – Free – Windows version… Start Daemon – Mysqld-nt.exe Download.
Servlets and JDBC. Servlets A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password:
Distributed Application Development B. Ramamurthy.
Fundamentals, Design, and Implementation, 9/e Chapter 14 JDBC, Java Server Pages, and MySQL.
15-Jun-15 JDBC. JDBC is a Sun trademark It is often taken to stand for Java Database Connectivity Java is very standardized, but there are many versions.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Server Side Web Technologies: Part 2.
Advanced Java Programming – Eran Toch Methodologies in Information System Development Tutorial: Advanced Java Programming and Database connection Eran.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password:
Murali Mani Web Interface. Murali Mani Options PHP with mySQL JSP/Servlets with JDBC on mySQL/Oracle Others …
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
M.Sc. Course, Dept. of Informatics and Telecommunications, University of Athens S.Hadjiefthymiades “Web Application Servers” Basics on WAS WAS are necessary.
Basic JDBC Use Oracle JDBC Drivers must be in the CLASSPATH
ECE356 – Database Systems Lab 1 – Building a Web Project with NetBeans Tiuley Alguindigue Lab Instructor – University of Waterloo, E & CE Dept. Fall 2013.
SERVLETS.
Java Server Programming Jeff Schmitt Towson University October 15, 1998.
TUTORIAL (1) Software installation Written by: Eng. Ahmed Mohamed Abdel Ghafar, Edited by Eng. Muhammed Hammad, Eng. Hamdy Soltan & Eng. Osama Talaat.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
1 Web Database Processing. Web Database Applications Static Report Publishing a report is prepared from a database application and exported to HTML DB.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
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
Think Possibility Integrating Web Applications With Databases.
Database Management Systems 1 Oracle Programming.
CSE470 Software Engineering Fall Database Access through Java.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
E-COMMERCE JOBS This project (Project number: HU/01/B/F/PP ) is carried out with the financial support of the Commssion of the European Communities.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
JDBC. JDBC Drivers JDBC is an alternative to ODBC and ADO that provides database access to programs written in Java.
Views, Indexes and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Haiman Tian 1.
CSE 305 Theory of Database Tutorial on Connecting with Sybase from Java program and Developing GUI Jalal Mahmud, TA, CSE 305.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
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.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
JAVA Database Access. JDBC The Java Database Connectivity (JDBC) API is the industry standard for database- independent connectivity between the Java.
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
CS 405G: Introduction to Database Systems Database programming.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
Java Programming, 2E Introductory Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
CS 160: Software Engineering October 1 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Index and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Leman Akoglu 11/11/ Fall 2009 Recitation Homework 9 Building A Web Application Phase-II School of Computer Science.
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
1 Introduction to Web Applications & APIs. 2 Agenda  Architecture of Web Applications Three layer architecture  Web Server (Tomcat) Installation Data.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
EXAMPLE I An application showing JDBC access to Cloudscape.
JSP Server Integrated with Oracle8i Project2, CMSC691X Summer02 Ching-li Peng Ying Zhang.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
Tasks Needed for MissionMapEditor Martin Q. Zhao September 18, 2010.
CSI 3125, Preliminaries, page 1 JDBC. CSI 3125, Preliminaries, page 2 JDBC JDBC stands for Java Database Connectivity, which is a standard Java API (application.
Basics of JDBC.
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
1 Database Management Systems (II) Chapter 14. JDBC, Java Server Pages, and MySQL © 2005 by Dr. F. Lin.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Settings MySQL Database and JDBC configuration Instructor: Sergey Goldman.
1. Writing a Java program to connect to SQL Server 2008 and Create a table Populate the table (insert data) Perform queries to retrieve information from.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
Instructor: Jinze Liu Fall /8/2016Jinze University of Kentucky 2 Database Project Database Architecture Database programming.
Database Programming Basic JDBC Programming Concepts.
Apache Tomcat & Quick Tutorial
Chapter 14. JDBC, Java Server Pages, and MySQL
Advanced Web Automation Using Selenium
PHP / MySQL Introduction
Java Database Connectivity
Presentation transcript:

1 Download current version of Tomcat from: g/tomcat/ g/tomcat/ Install it in: C:\Program Files\Apache Software Foundation\Tomcat 5.5\ Test it: Directory structure \Tomcat 5.5 \webapps\common\bin…\lib \ROOT…

2 An simple JSP example: test.jsp A Test of JSP Welcome! Today is:.

3 An simple JSP example (con’t) Edit it using an editor, e.g. WordPad. Save it in: C:\Program Files\Apache Software Foundation\Tomcat5.5\webapps\ROOT\test.jsp Start Tomcat: C:\Program Files\Apache Software Foundation\Tomcat5.5\bin\tomcat5 Open a Web browser and go to:

4 Running JSP JSP compilation process: parse, compile, load and execute JSP Page Request JSP Servlet Current? JSP Servlet in Memory? Parse JSP and Create Java Source File Compile Java Source File Execute the JSP servlet Load the JSP servlet JSP Page Response no yes no

5 Figure 14-6: GeneralTable.jsp Table Display Using JDBC and MySQL Database Access Example <%String varTableName= request.getParameter("Table"); varTableName = varTableName.toUpperCase(); %> Showing Data from MySQL Database db1

6 <% try { // Load JDBC driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); String connString="jdbc:odbc:test"; System.out.println("Trying connection with "+connString); Connection conn = DriverManager.getConnection(connString); Statement stmt = conn.createStatement(); String varSQL = "SELECT * FROM " + varTableName; ResultSet rs = stmt.executeQuery(varSQL); ResultSetMetaData rsMeta = rs.getMetaData(); %>

7 <% String varColNames = ""; int varColCount = rsMeta.getColumnCount(); for (int col =1; col <= varColCount; col++) { %> <% while (rs.next()) { %> <% for (int col=1; col<=varColCount; col++) { %> <FONT SIZE=2 FACE="Arial" COLOR=# > <% } }

8 //clean up rs.close(); stmt.close(); conn.close(); } catch (ClassNotFoundException e) { out.println("Driver Exception " + e); } %> Example: Run it!Run it!

9 Java Bean Model 1.

10 JSP invoking Java Classes (Java Beans) Important and Useful: –It separates the tasks of writing program logic from generating HTML; –It Reduces the complexity of managing a Web site. Java Bean –A properly mannered Java class; –A Java class that has three properties: there are no public instance variables; All persistent values xxx are accessed using methods named getxxx and setxxx Bean classes must either have no constructors or it must have one explicitly defined zero- argument constructor

11 An example using Java Bean Save it into: C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\classes\ Compile it: >javac CustomerInsertBean.java We get CustomerInsertBean.class Edit NewCustomer.html Save it into: C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\ Edit CustomerInsertUsingBean.jsp Save it into C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\ Start Tomcat C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin\tomcat5

12 An Example using Java Bean and JDBC JSP: Display the result set retrieved from Table Testinfo in the database db1 Use the Java Bean DBUtil_MySQL.class Java: Load the JDBC driver Set up the connection Get the ResultSet

13 An example using Java Bean and MySQL // A Java Bean source code: DBUtil_MySQL.java package lin; import java.io.*; import java.sql.*; public class DBUtil_MySQL { // For MySQL String sDBDriver="com.mysql.jdbc.Driver"; String sConnStr="jdbc:mysql://localhost:3307/"+"db1"+"?user=root"; // for MS ACCESS //String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver"; //String sConnStr="jdbc:odbc:test"; Connection conn = null; ResultSet rs = null; public DBUtil_MySQL() { try { //java.sql.DriverManager.registerDriver(); Class.forName(sDBDriver); } catch(java.lang.ClassNotFoundException e) { System.err.println("testJDBC(): " + e.getMessage()); } } It is necessary to use a package, Otherwise something will go wrong.

14 An example using Java Bean and MySQL public ResultSet executeQuery(String testJDBC) { rs = null; try { conn=DriverManager.getConnection(sConnStr); Statement stmt = conn.createStatement(); rs=stmt.executeQuery(testJDBC); } catch(SQLException ex) { System.err.println("aq.executeQuery:"+ex.getMessage()); } return rs; } Save it in: \webapps\ROOT\WEB-INF\classes\DBUtil_MySQL.java >javac –d \ DBUtil_MySQL.java Copy the file we got from the compilation DBUtil_MySQL.class in C:\lin to C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB- INF\classes\lin\

15 testDB_MySQL.jsp MY FAQ This is my name! page language="java" import ="java.sql.*" pageEncoding="gb2312" %> <% ResultSet RS = workM.executeQuery("SELECT * FROM testinfo"); while (RS.next()) { ResultSet rs = workM.executeQuery("SELECT * FROM testinfo"); String str_name, str_gender; out.println("Get data from a database:: "); %> <% while (rs.next()) { str_name=rs.getString("name"); str_gender = rs.getString("gender"); out.println(" name is: " + str_name); out.println(" gender is: " + str_gender); %> <% } } RS.close(); %> Save it to: C:\Program Files\ Apache Software Foundation \Tomcat 5.5\webapps\ROOT\ Go to:

16 MySQL Downloading MySQL –An open-source DBMS product that runs on Unix, Linux, and Windows Provides quick and efficient query handling Allows you to create users, databases, tables, auto incrementing fields, etc. –The MySQL open-source driver may be downloaded from:

17 Get and Install a Recent Version Download the 4.0 and/or 4.1 versions of the MySQL win32 distribution Find the downloaded file, unzip it and start the setup program: By referring to de/mybasic.htm de/mybasic.htm Install it to C:\Program Files\mysql40\ Start it: C:\Program Files\mysql40\bin\

18 –Limitations While MySQL is extremely inexpensive and provides many capabilities, it is not as powerful as commercial products, such as Oracle and SQL Server –Using My SQL MySQL commands: use, show, describe

19 Using MySQL >mysql –P 3307 –u root mysql >Show databases; >sHow databases; (OK) >Use db1; >Show tables; >Describe testinfo; >Select * from testinfo; Or >\q Edit sql.txt >bin>mysql –P 3307 –u root mysql <C:\wan\sql.txt

20 MySQL Connector/J –The latest version of the driver is MySQL Connector/J (formerly MM.MySQL driver) is a Java driver that converts JDBC calls into the network protocol used by the MySQL database. is a Type 4 JDBC driver and has a complete JDBC feature set that supports the capabilities of MySQL. Download the driver from Unzip it to get the jar file: mysql-connector-java ga-bin.jar copy it to a public place: …\Tomcat 5.5\common\lib\mysql-connector-java ga-bin.jar

21 –JDBC connections JDBC connection to MySQL is different from other user connections –Same machine: via socket –Different machines: via TCP/IP

22 –A work-around allows you to grant access to the for the specific account »The wildcard % states that the database may be accessed from any host »Alternatively, you may supply the specific IP address for your local machine –this provides better security –Concurrency control Limited support: read/write locks –Backup and recovery Limited support: database/table saving, log files

23 Summary JDBC –JDBC driver types –Java Servlet and Applets –JDBC architecture and components –Applications of JDBC JSP (Java Server Pages) –JSP, Servlets and Apache Tomcat MySQL –MySQL and JDBC Connections; Concurrency control, and backup and recovery Questions?