JSP and DB.

Slides:



Advertisements
Similar presentations
Basic JDBC Celsina Bignoli What is JDBC Industry standard for database- connectivity between the Java language and a wide range of.
Advertisements

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.
1 JDBC Java Database Connectivity. 2 c.pdf
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
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.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
1 CSC 440 Database Management Systems JDBC This presentation uses slides and lecture notes available from
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Database Programming in Java Corresponds with Chapter 32, 33.
Views, Indexes and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Haiman Tian 1.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
 What software components are required?  How do I install the Oracle JDBC driver?  How do I connect to the database?  What form is the data in and.
Introduction to JDBC Michelle Lee, Ye Wu & Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
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.
1 JDBC Aum Amriteshwaryai Namah. 2 2 JDBC – Java DataBase Connectivity.
Index and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
Java Database Connectivity (JDBC). Topics 1. The Vendor Variation Problem 2. SQL and Versions of JDBC 3. Creating an ODBC Data Source 4. Simple Database.
Java Database Connectivity. Java and the database Database is used to store data. It is also known as persistent storage as the data is stored and can.
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.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
Li Tak Sing COMPS311F. Database programming JDBC (Java Database Connectivity) Java version of ODBC (Open Database Connectivity) ODBC provides a standard.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
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.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 8: Applications Programming for Relational Databases Instructor’s.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Web Programming Assistant Professor Xiaozhong Liu
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.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
JSP/Database Connectivity Instructor: Dr. M. Anwar Hossain.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
Database Processing with JSP ISYS 350. Database Applications Applications Database Server Queries/Updates Results.
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.
SCU Fall 2002JoAnne Holliday10–1 Schedule Today u Embedded SQL. u Read Sections 8.1, 8.5. Next u Transaction concepts, security u Read Sections 8.6 – 8.7.
CompSci 280 S Introduction to Software Development
Database: JDBC Overview
DEPTT. OF COMP. SC & APPLICATIONS
CS3220 Web and Internet Programming Database Access with JDBC
Lec - 14.
JDBC Database Management Database connectivity
JDBC – Java Database Connectivity
CS320 Web and Internet Programming Database Access with JDBC
Database JDBC Overview CS Programming Languages for Web Applications
Advanced Web Automation Using Selenium
HW#4 Making Simple BBS Using JDBC
JDBC – ODBC DRIVERS.
Using a Database with JDBC
JDBC Example.
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

JSP and DB

A web application is nothing more than a front end for a database (DB). what makes web pages dynamic is precisely the fact that there is a significant amount of data behind them. In JAVA, we USE JDBC API to access DBs from an application.

JDBC JAVA Database Connectivity. Provides a mean for JAVA applications to access different kind of DBMS through a JDBC driver. The JDBC API provides a call-level API for SQL-based database access.

Through JDBC you can: Establish a connection with a database. Send an SQL statements to the DB. And process the results.

Establishing a JDBC connection First, you need to establish a connection with the data source you want to use. A data source can be a DBMS, a legacy file system, or some other source of data with a corresponding JDBC driver. Typically, a JDBC application connects to a target data source using one of two classes: DriverManager: This fully implemented class connects an application to a data source, which is specified by a database URL. OR, DataSource: 

Establishing a JDBC connection In both methods you need to provide the DB URL, user name and password (collectively knows as a connection string). I.e: Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost:8888/ebookshop", "myuser", “mypass");

Establishing a JDBC connection Typically, in the database URL, you specify the name of an existing database to which you want to connect. For example, the URLjdbc:mysql://localhost:3306/mysql  represents the database URL for the MySQL database named mysql.

Create an SQL statement create an object of type java.sql.Statement. Statement stmt = conn.createStatement(); The Statement class has 40 methods, plus some more inherited ones. Nevertheless, two methods are likely to satisfy most of your needs: executeQuery and executeUpdate.

Create an SQL statement We want to create a statement that retrieve a book_Id, title and author from a DB through JDBC driver: 1. Define the JDBC connection object: Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost:8888/ebookshop", "myuser", “mypass");

2. create an object from the Statement class and pass to it the previous conn object: Statement stmt = conn.createStatement(); 3. Defiene a string that containing the actual SQL statement: String sql = "select book_id, title, author from books where category_id=1 order by author, title"; 4. Execute the Statement against the DB: ResultSet rs = stmt.executeQuery(sql);

Accessing the data from the ResultSet: At any given time, you can only access the row of the result set pointed to by the so-called cursor. The usual way of accessing the rows of the result set is to start from the first one and “go down” in sequence.

while (rs.next()) { out.println(rs.getString(3) + ", " + rs.getString(2) + "<br/>"); } would produce the following output: Damon Williams, Pro PayPal E-Commerce. Michael Bowers, Pro CSS and HTML Design Patterns.

The next method moves the cursor down one row The next method moves the cursor down one row. After the cursor goes past the last row, next() returns false, and the while loop terminates. Initially, the cursor is positioned before the first row. Therefore, you have to execute next() once in order to access the very first row.

The ExecuteUpdate() Method You use the executeUpdate method to execute the SQL statements insert, update, and delete. For example, if you want to add a new book category to the online bookshop example, you do something like this: String sql = "insert into categories (category_id, category_name)" + " values (4, 'Comic Books')"; stmt.executeUpdate(sql);