Views, Indexes and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Haiman Tian 1.

Slides:



Advertisements
Similar presentations
CE203 - Application Programming Autumn 2013CE203 Part 51 Part 5.
Advertisements

CMPT 354 Views and Indexes Spring 2012 Instructor: Hassan Khosravi.
What is MySQL? MySQL is a relational database management system (A relational database stores data in separate tables rather than putting all the data.
JDBC. Java Database Connectivity (JDBC) Use the java.sql package to query and update the database. JDBC is an API that allows java to communicate with.
Distributed Application Development B. Ramamurthy.
1 JDBC Java Database Connectivity. 2 c.pdf
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
CS34311 CS3431 – Database Systems I Project Overview Murali Mani.
Java Database Connectivity (JDBC) java.sql package to query and update the database. JDBC is an API that allows java to communicate with a database server.
Introduction to Structured Query Language (SQL)
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
Murali Mani Web Interface. Murali Mani Options PHP with mySQL JSP/Servlets with JDBC on mySQL/Oracle Others …
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
1 CSC 440 Database Management Systems JDBC This presentation uses slides and lecture notes available from
CSCI 6962: Server-side Design and Programming
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
Jaeki Song JAVA Lecture 11 Java Database Connectivity.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
Database Programming in Java Corresponds with Chapter 32, 33.
Movie Manager by Patrick Wesley and Chris Grey Internet Database Project for CS 8630 – Summer 2004 Dr. Guimaraes.
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.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 MySQL and JDBC.
JAVA Database Access. JDBC The Java Database Connectivity (JDBC) API is the industry standard for database- independent connectivity between the Java.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Introduction to CS520/CS596_026 Lecture Two Gordon Tian Fall 2015.
Index and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Chapter 8 Databases.
Copyright  Oracle Corporation, All rights reserved. 6 Accessing a Database Using the JDBC API.
Chapter 25 Databases. Chapter Scope Database concepts Tables and queries SQL statements Managing data in a database Java Foundations, 3rd Edition, Lewis/DePasquale/Chase25.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
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.
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.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 8: Applications Programming for Relational Databases Instructor’s.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
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.
1 JDBC – Java Database Connectivity CS , Spring 2010.
1 Download current version of Tomcat from: g/tomcat/ g/tomcat/ Install it in: C:\Program Files\Apache.
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.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
Jennifer Widom Indexes. Jennifer Widom Indexes  Primary mechanism to get improved performance on a database  Persistent data structure, stored in database.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
Database Programming Basic JDBC Programming Concepts.
JSP and DB.
3 A Guide to MySQL.
CS320 Web and Internet Programming Database Access with JDBC
HW#4 Making Simple BBS Using JDBC
JDBC.
Views, Indexes and JDBC/JSP tutorial
Indexes.
MSIS 655 Advanced Business Applications Programming
Tutorial Unix Command & Makefile CIS 5027
Bolat Azamat, Kim Dongmin
JDBC Example.
Lecture 11 Database Connection
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Presentation transcript:

Views, Indexes and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Haiman Tian 1

Outline  Introduction of Views  Introduction of Indexes  Instruction to access PostgreSQL from Tomcat 1. Setup Tomcat in your Unix account 2. Write down the info output by the script 3. Copy jdbc to the common/lib folder of tomcat 4. Create a jsp page to access your PostgreSQL database  JDBC 2

Views  A selective presentation of the structure of, and data in, one or more tables (or other views)  A ‘virtual table’, having predefined columns and joins to one or more tables, reflecting a specific facet of information  Structure data in a way that users or classes of users find natural or intuitive.  Restrict access to the data such that a user can only see limited data instead of complete table.  Summarize data from various tables which can be used to generate reports.

Example CREATE VIEW myview AS SELECT city, temp_lo, temp_hi, prcp, date, location FROM weather, cities WHERE city = name; SELECT * FROM myview; DROP VIEW myview;

Indexes

 Primary mechanism to get improved performance on a database  Persistent data structure, stored in database  Many interesting implementation issues

Functionality ABC 1 cat 2… 2 dog 5… 3 cow 1… 4 dog 9… 5 cat 2… 6 8… 7 cow 6… … …… Index on T.A T T.A = ‘cow’ T.A = ‘cat’

Index on T.A Functionality ABC 1 cat 2… 2 dog 5… 3 cow 1… 4 dog 9… 5 cat 2… 6 8… 7 cow 6… … …… Index on T.B T T.B = 2 T.B < 6 4< T.B <= 8

Index on T.A Functionality ABC 1 cat 2… 2 dog 5… 3 cow 1… 4 dog 9… 5 cat 2… 6 8… 7 cow 6… … …… Index on T.B Index on T.(A,B) T T.A = ‘cat’ and T.B > 5 T.A < ‘d’ And T.B = 1

Utility  Index = difference between full table scans and immediate location of tuples  Orders of magnitude performance difference  Underlying data structures – Balanced trees (B trees, B+ trees) – Hash tables A=V, A<V, V 1 < A < V 2 A=V

Select sName From Student Where sID = Many DBMS’s build indexes automatically on PRIMARY KEY (and sometime UNIQUE) attributes Index on sID

Select sID From Student Where sName = ‘Mary’ And GPA > 3.9 Index on sName Index on GPA Index on (sName, GPA) Tree-based Hash-based or Tree-based

Downsides of Indexes 1) 2) 3) Extra space- Marginal Index creation- Medium Index maintenance- Can offset benefits

Picking which indexes to create Benefit of an index depends on:  Size of table (and possibly layout)  Data distributions  Query vs. update load

SQL Syntax Create Index IndexName on T(A) Create Index IndexName on T(A1,A2,…,An) Create Unique Index IndexName on T(A) Drop Index IndexName

Outline  Introduction of Views  Introduction of Indexes  Instruction to access PostgreSQL from Tomcat 1. Setup Tomcat in your Unix account 2. Write down the info output by the script 3. Copy jdbc to the common/lib folder of tomcat 4. Create a jsp page to access your PostgreSQL database  JDBC 16

(1) Setup Tomcat in your Unix account  Log into ocelot.aul.fiu.edu by using putty through ssh 17

(1) Setup Tomcat in your Unix account  Log into ocelot.aul.fiu.edu  User : FIU account  Password : Your first initial, followed by your Panther ID, followed by your last initial.  Make sure your JAVA_HOME environment variable is set to /depot/J2SE-1.7  Using the tech shell (most users use this)  setenv JAVA_HOME /depot/J2SE

(1) Setup Tomcat in your Unix account  Run this script  /home/ocelot/tomcat/install-tomcat-cop4710.sh  cd /home/ocelot/tomcat ./install-tomcat-cop4710.sh  Additional instructions will be provided after running this script and it will also tell you which port is assigned to you.  Note that if you do not have your JAVA_HOME environment variable set correctly, you will have problems running Tomcat. 19

20

21  Start Tomcat . /tomcat-cop4710/bin/startup.sh (1) Setup Tomcat in your Unix account

(3) Copy jdbc  Copy jdbc to the common/lib folder of tomcat  Download PostgreSQL JDBC driver from

(4) Create a jsp page  Put the file in the ROOT folder in the Application directory 23

(4) Create a jsp page 24

(4) Create a jsp page 25

Outline  Introduction of Views  Introduction of Indexes  Instruction to access PostgreSQL from Tomcat 1. Setup Tomcat in your Unix account 2. Write down the info output by the script 3. Copy jdbc to the common/lib folder of tomcat 4. Create a jsp page to access your PostgreSQL database  JDBC 26

JDBC  Write once, Match all DBMS!!  The Java Database connectivity  Making a connection to a database  Creating SQL or MySQL statements  Executing queries in the database  Viewing or Modifying the result records Application JDBC Driver Interface Oracle JDBC Driver SQL JDBC Driver MySQL JDBC Driver PostgreSQL JDBC Driver Oracle Database SQL Database MySQL Database PostgreSQL Database 27

Steps of connecting database 1) Get the specific type of JDBC driver 2) Initializing the Driver 3) Start the Connection 4) Initialize one Statement object 5) Send out the SQL execute*() 6) Get the Resultset object which is returned by DBMS 7) Close the connection close() 28

(1) Get JDBC driver Download driver from any DBMS company website Format: For example: postgresql jdbc4.jar Put it to any accessible library folder PostgreSQL JDBC Driver : 29

(2) Initializing the Driver  Importing JDBC  Import java.sql.*  Loading the server  Class.forName("org.postgresql.Driver"); try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException e) { System.out.println(“Can’t find Driver class "); } 30

(3) Start the connection  String DRIVER = "org.postgresql.Driver"; String URL ="jdbc:postgresql://[IP]:5432/[DB_Name]"; String USER = "whoami"; String PASSWORD = "123456"; Connection conn = DriverManager.getConnection( URL, USER, PASSWORD ); // DriverManager.getConnection( url ); System.out.println(conn.isReadOnly( ));... if ( conn != null && !conn.isClosed( ) ) { System.out.println(“Successfully connect to database ! "); } conn.close( ); 31

(4) Initialize one Statement object and (5)execute  Execute  executeQuery() -> SQL for Searching and viewing  executeUpdate() -> SQL for Changing database’s contents  ExecuteQuery()  Return results as row(s)  Use next() to move to next record, return a boolean value to indicate whether we have next record  Use get () to retrieve the data by attribute name or order Statements stmt = conn.createStatement( ); ResultSet result = stmt.executeQuery(“SELECT * FROM myTable”); 32

Execute Example  Create / Update table  View data Statements stmt = conn.createStatement( ); stmt.executeUpdate( "CREATE TABLE jdemo ( title character varying(50),body text, id serial)"); stmt.executeUpdate(“ALTER TABLE jdemo ADD PRIMARY KEY (id)”); ResultSet result = stmt.executeQuery(“SELECT * FROM jdemo”); while (result.next( )) { System.out.print(result.getInt(“id”) + “\t”); System.out.print(result.getString("title") + "\t"); System.out.println(result.getString("body")); } 33

References  PostgreSQL INDEX syntax  createindex.html createindex.html  JSP tutorial webstie 