JSP/Database Connectivity Instructor: Dr. M. Anwar Hossain.

Slides:



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

19 augustus 2003augustus 2003 JSP-2. BICT 2JDBC BICT 3Install MySQL Download MySQL daemon – Free – Windows version… Start Daemon – Mysqld-nt.exe Download.
Java, Access, SQL, HTML. Three-tier architecture involves: Client - Browser Server - Tomcat Database - Access - Server-side language - JSP could just.
Object Oriented Programming Java Java’s JDBC Allows access to any ANSI SQL-2 DBMS Does its work in terms of SQL The JDBC has classes that represent:
EmbeddedSQL: 1 Impedance Mismatch Problem Problem : How to connect SQL statements with conventional programming languages Different models of language.
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
Java MS Access database connectivity Follow these steps: 1)Go to the start->Control Panel->Administrative Tools- > data sources. 2)Click Add button and.
Overview 1. What is JDBC? 2. The JDBC-ODBC Bridge 3. JDBC Pseudocode 4. simpJDBC.java.
Lab: JDBC 1 Computer Engineering Lab III v Objective –to give some background on JDBC to help with the lab exercises , Semester 1,
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
CS178 Database Management “JDBC”. What is JDBC ? JDBC stands for “Java DataBase Connectivity” The standard interface for communication between a Java.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
JDBC. JDBC Drivers JDBC is an alternative to ODBC and ADO that provides database access to programs written in Java.
Databases: Queries with Java Dr Andy Evans. JDBC SQL Three methods: Statements: Standard, simple, SQL. PreparedStatements: Compiled SQL statements that.
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.
JDBC Java and Databases, including Postgress. JDBC l Developed by Industry leaders l Three main goals: –JDBC should be an SQL-level API –JDBC should capitalize.
Computer Engineering Lab
CS 160: Software Engineering October 1 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
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.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
JSP program that interacts with HTML form & Access Data Base.
Chapter 8 Databases.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
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.
Web Design & Development 1 Lec Web Design & Development 2 More on JDBC.
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.
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 Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Connecting to MySQL using Java By:. – Required to use Java.sql so that we can use Connection and Queries using strings. – Javax.swing.* needed for components.
Basics of JDBC.
JDBC (Java Database Connectivity)
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Web Programming Assistant Professor Xiaozhong Liu
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
JDBC I IS Why do we have databases?
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.
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.
MySQL root 암호 $ mysqladmin -u root -p password new-password $ mysql -u root mysql mysql> update user set password = password('new-password') where user.
Database Programming Basic JDBC Programming Concepts.
JSP and DB.
CompSci 280 S Introduction to Software Development
JDBC and OCCI 10/29/2017.
CS3220 Web and Internet Programming Database Access with JDBC
Java Access to RDB Relational databases (RDBs) dominate today, due to:
Lec - 14.
CS320 Web and Internet Programming Database Access with JDBC
Advanced Web Automation Using Selenium
Client Access, Queries, Stored Procedures, JDBC
Introduction to Server-Side Web Development using JSP and Databases
JDBC API.
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/Database Connectivity Instructor: Dr. M. Anwar Hossain

Accessing a Database: Processing Steps 1. Load a driver which is compatible with the database that is to be processed. 2. Define and establish a connection to the database. 3. Associate an SQL statement with this connection. 4. Execute the SQL statement. 5. The SQL statement which has been executed will produce a table which is stored in a ResultSet object. This object will contain a reference to the rows of the table that has been formed by the execution of the SQL statement. 6. Execute further SQL statements as above. 7. When the processing associated with the database is complete the database is closed and the connection to the database is also closed.

Accessing a Database: Processing Steps Example 1. Class.forName("org.gjt.mm.mysql.Driver"); 2. Connection conn = DriverManager.getConnection( "jdbc:mysql://mysql0.ee.surrey.ac.uk:3306/webtech", "webtech", "webtech"); 3. Statement st = conn.createStatement(); 4. ResultSet rs=st.executeQuery("SELECT * FROM images"); 5. while(rs.next()){ anInteger = rs.getInteger(1); aString = rs.getString(2); } 7. st.close(); rs.close(); conn.close();

Define and Establish the Connection Create a connection object Connection conn = null; Load the JDBC driver and connect to the database Class.forName("driver..."); conn = DriverManager.getConnection("url...", [Username], [Password]); NOTE: All functions of connecting and using a database should be enclosed within a try-catch block. NOTE: A database connection should always be closed after the code has finished using the database.

Create a Statement Object and Execute Create a Statement object and execute the SQL Statement st = conn.createStatement(); // for selecting records ResultSet rs = st.executeQuery("query..."); or // for inserting, deleting or updating records int numRows = st.executeUpdate("query..."); NOTE: Capturing exceptions is important and should not be ignored

Process the Results Process the ResultSetMetaData ResultSetMetaData rm = rs.getMetaData(); rm.getColumnCount(); // Number of columns rm.getColumnName(1); // Name of column rm.getColumnType(1); // Data type of column Process the ResultSet rs.next(); // move to next record, returns boolean rs.getXxx(); rs.getString(1); // using column id rs.getString("name"); // using column name rs.getInteger(2); Rs.getObject(3);

Example: Displaying results on a Table First (based on previous 3 slides): Define and Establish the Connection Create a Statement Object and Execute the SQL Get the ResultSetMetaData and ResultSet Then, get number of columns and build a list of column names int columns = rm.getColumnCount(); result = " "; for ( int i = 1; i <= columns; i++){ result += " " + rm.getColumnLabel(i) + " "; } result += " ";

Example: Displaying results on a Table Then, get the actual data while(rs.next()) { result += " "; for ( int i = 1; i <= columns; i++) { result += " " + rs.getObject(i).toString() + " "; } result += " "; } Close the Statement, ResultSet, and Connection st.close(); rs.close(); conn.close(); Eventually, you print the results on a JSP page