Design and Implementation of Software for the Web

Slides:



Advertisements
Similar presentations
Copyright  Oracle Corporation, All rights reserved. 2 Java and Databases: An Overview.
Advertisements

JDBC CS-328. JDBC Java API for accessing RDBMS Allows use of SQL for RDBMS programming Can be used for: –embedded SQL –execution of stored queries.
1 JDBC Java Database Connectivity. 2 c.pdf
1 JDBC: Java Database Connectivity. 2 Introduction to JDBC JDBC is used for accessing databases from Java applications Information is transferred from.
1 JDBC: Part I Attribution These slides are based on three primary sources: –Sun JDBC Tutorial URL: jdbc/TOC.htmlhttp://java.sun.com/docs/books/tutorial/
Java Database Connectivity JDBC ICW Lecture 12 Errol Thompson.
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Web Application Development Muhammad Ali Versonic Pte Asher Imtiaz Forman Christian College.
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
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
Java Database Connectivity ASE. Java Database Connectivity (JDBC) l JDBC – provides an interface to Relational Data Sources l JDBC library provides the.
1 JDBC – Java Database Connectivity Modified slides from Dr. Yehoshua Sagiv.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
Java + XML. Java 2 Enterprise Edition Server Side java Servlets JSP JavaBeans Web Services Database jdbc.
Introduction to JDBC Michelle Lee, Ye Wu & Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
1 JDBC – Java Database Connectivity. 2 Introduction to JDBC JDBC is used for accessing databases from Java applications Information is transferred from.
1 JDBC Aum Amriteshwaryai Namah. 2 2 JDBC – Java DataBase Connectivity.
JDBC – Java DataBase Connectivity. JDBC API Overview JDBC is Java API that allows the Java programmers to access database management system from Java.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
Chapter 8 Databases.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
Copyright  Oracle Corporation, All rights reserved. 6 Accessing a Database Using the JDBC API.
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.
Session 30 Basics of JDBC. Java Simplified / Session 30 / 2 of 33 Review A Swing menu consists of a menubar, menuitems and menus. Trees are used to depict.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
JDBC™ Fundamentals (a.k.a. Java Database Connectivity, although technically not an acronym) ©SoftMoore ConsultingSlide 1.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
JDBC Part II CS 124. More about JDBC Types Statement versus PreparedStatement Timeout NULL values Meta-data close() methods Exceptions Transactions JDBC.
Basics of JDBC Session 14.
JDBC Java DataBase Connectivity. Loading the driver import java.sql.*... Class.forName("org.postgresql.Driver")‏
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
6-1 JAVA DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
1 JDBC – Java Database Connectivity THETOPPERSWAY.COM.
JDBC – Java DataBase Connectivity
Database: JDBC Overview
Note: To complete the examples in this section you need access to a database!! Most of the examples work for any database with JDBC drivers. However, connecting.
Course Outcomes of Advanced Java Programming AJP (17625, C603)
JDBC – Java Database Connectivity
JDBC & Servlet CSE 4504/6504 Lab.
Database JDBC Overview CS Programming Languages for Web Applications
JDBC – Java Database Connectivity
HW#4 Making Simple BBS Using JDBC
Part 4 FaaDoOEngineers.com IBM.
JDBC – Java DataBase Connectivity
JDBC – Java DataBase Connectivity
Objectives In this lesson, you will learn about:
Interacting with Database
JDBC – ODBC DRIVERS.
JDBC – Java Database Connectivity
JDBC Example.
Java Database Connectivity JDBC
JDBC – Java DataBase Connectivity
Presentation transcript:

Design and Implementation of Software for the Web JDBC Overview Jeff Offutt http://www.cs.gmu.edu/~offutt/ SWE 432 Design and Implementation of Software for the Web

JDBC JDBC (Java Database Connectivity) API allows Java programs to connect to databases Database access is the same for all database vendors The JVM uses a JDBC driver to translate generalized JDBC calls into vendor specific database calls There are four general types of JDBC drivers We will look at Type 4 … 13 October 2018 © Offutt

JDBC = Java Data Base Connectivity ? Many people believe that JDBC stands for Java Data Base Connectivity But not quite—here is the link from Sun stating that JDBC is not an acronym: http://java.sun.com/docs/books/jdbc/intro.html Excerpt : “JDBC (TM) is a Java (TM) API for executing SQL statements. (As a point of interest, JDBC is a trademarked name and is not an acronym; nevertheless, JDBC is often thought of as standing for `Java Database Connectivity’.) ” 13 October 2018 © Offutt

Pure Java Driver (Type 4) Server Data Source DB Client Java Application JDBC API JDBC Driver Converts JDBC calls to network calls — Direct socket connections Type 4 drivers are Efficient Simple to use and deploy Most commonly used 13 October 2018 © Offutt

Typical JDBC Programming Procedure Load the database driver Obtain a connection Create and execute statements Use result sets to navigate through the results Close the connection 13 October 2018 © Offutt

Driver Manager The java.sql.DriverManager class in JDBC provides a common access layer on top of different database drivers DriverManager requires that each driver used by the application must be registered before use Load the database driver using ClassLoader : Class.forName (“oracle.jdbc.driver.OracleDriver”); forName(“..”): At run time, the ClassLoader loads the class from the Classpath USING THE BOOTSTRAP CLASS LOADER. While loading a class, the class loader executes any static initialization code for the class. In JDBC, each driver provider is required to register an instance of driver with during this initialization. 13 October 2018 © Offutt

Connecting to a Database Type 4 JDBC Driver Oracle Server Class.forName ("oracle.jdbc.driver.OracleDriver"); con = DriverManager.getConnection ( "jdbc:oracle:thin:@apollo.ite.gmu.edu:1521:ite8i", "swe432", "swe432"); MySQL Server Class.forName ("org.gjt.mm.mysql.Driver"); con = DriverManager.getConnection ("jdbc:mysql://localhost/databasename", uid, passwd); 13 October 2018 © Offutt

Creating and Executing SQL Statements Statement object Statement statement = con.createStatement(); statement.executeUpdate (“CREATE TABLE STUDENT”); statement.executeQuery (“SELECT * FROM STUDENT”); 13 October 2018 © Offutt

Creating Tables Examples Creating a Coffee table CREATE TABLE COFFEES (COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, SALES INTEGER, TOTAL INTEGER) Creating JDBC statements Statement stmt = con.createStatement (); Execute a statement stmt.executeUpdate ("CREATE TABLE COFFEES " + "(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT,” + "SALES INTEGER, TOTAL INTEGER)"); SQL query 13 October 2018 © Offutt

Checking to See if a Table Exists Use meta data about the table DatabaseMetaData dmd  = con.getMetaData(); ResultSet rs = dmd.getTables (null, null, “COFFEES", null); if (rs == null) {       // table does not exist, create it. } 13 October 2018 © Offutt

Execute Statements This uses executeUpdate because the SQL statement contained in createTableCoffees is a data definition language ( DDL ) statement DDL statements are executed with executeUpdate Create a table Alter a table Drop a table executeUpdate is also used to execute SQL statements that update a table 13 October 2018 © Offutt

Execute Statements executeUpdate is used more often to update tables than it is to create them We create a table once but updated it many times executeQuery is used most often to execute SQL statements executeQuery is used to execute SELECT statements SELECT statements are the most common SQL statements 13 October 2018 © Offutt

Entering Data to a Table Statement stmt = con.createStatement(); stmt.executeUpdate ( "INSERT INTO COFFEES" + "VALUES ('Colombian', 101, 7.99, 0, 0)"); stmt.executeUpdate ("INSERT INTO COFFEES" + "VALUES ('French_Roast', 49, 8.99, 0, 0)"); stmt.executeUpdate ("INSERT INTO COFFEES" + "VALUES ('Espresso', 150, 9.99, 0, 0)"); stmt.executeUpdate ("INSERT INTO COFFEES" + "VALUES ('Colombian_Decaf', 101, 8.99, 0, 0)"); stmt.executeUpdate ("INSERT INTO COFFEES" + "VALUES ('French_Roast_Decaf', 49, 9.99, 0, 0)"); 13 October 2018 © Offutt

Getting and Using Data From Tables ResultSet rs = stmt.executeQuery ("SELECT COF_NAME, PRICE FROM COFFEES"); while (rs.next()) { String s = rs.getString ("COF_NAME"); float n = rs.getFloat ("PRICE"); System.out.println (s + " " + n); } 13 October 2018 © Offutt

Navigating Result Sets JDBC Types Mapped to Java Types JDBC Types Java Types CHAR String DATE Java.sql.Date VARCHAR TIME Java.sql.Time LONGVARCHAR TIMESTAMP Java.sql.Timestamp TINYINT short INTEGER Int JAVAOBJECT Object BIGINT Long BLOB Java.sql.Blob interface REAL Float CLOB Java.sql.Clob interface FLOAT Double ARRAY Java.sql.Array interface DOUBLE STRUCT BIT boolean REF 13 October 2018 © Offutt

Navigating Result Sets ResultSet rs = statement.exeuteQuery (“select * from student”); while (rs.next()) { System.out.print (rs.getString (“name”) + … } ResultSetMetaData metaData = rs.getMetaData(); metaData.getColumnCount(); metaData.getColumnName (I); metaData.getColumnType (I); 13 October 2018 © Offutt

Navigating Result Sets By default, a ResultSet object is read-only (not updateable) and has a cursor that moves forward only ( next() ). Scrollable result sets have more operations First, last, absolute, relative, next, previous, beforeFirst, afterLast, isFirst isBeforeFirst, isLast, isAfterLast 13 October 2018 © Offutt

JDBC Summary Most large web applications use databases to make data persistent The techniques for accessing databases from Java programs are identical in web applications as in stand-alone Java programs Read further for information on how to set up, use a database, and how to construct SQL queries 13 October 2018 © Offutt