Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.

Slides:



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

Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Basic JDBC Celsina Bignoli What is JDBC Industry standard for database- connectivity between the Java language and a wide range of.
Distributed Application Development B. Ramamurthy.
1 JDBC Java Database Connectivity. 2 c.pdf
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
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
CSE470 Software Engineering Fall Database Access through Java.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Accessing Databases with JDBC. Introduction to JDBC JDBC provides a standard library for accessing databases by using the JDBC API. JDBC standardizes.
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
Java Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
Think Possibility Integrating Web Applications With Databases.
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.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Database Programming in Java Corresponds with Chapter 32, 33.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui COMP 302 Database Systems Java Data Base Connectivity Lecturer Dr Pavle Mogin.
 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.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
Chapter 8 Databases.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
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 CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
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.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC.
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
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.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
1 JDBC – Java Database Connectivity CS , Spring 2010.
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.
JSP and DB.
Database: JDBC Overview
DEPTT. OF COMP. SC & APPLICATIONS
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.
Lec - 14.
JDBC – Java Database Connectivity
CS320 Web and Internet Programming Database Access with JDBC
HW#4 Making Simple BBS Using JDBC
Design and Implementation of Software for the Web
Objectives In this lesson, you will learn about:
Interacting with Database
JDBC – ODBC DRIVERS.
JDBC Example.
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Presentation transcript:

Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL

Persistence Retaining information in a database or file after a user request. Could be implemented using  Relational databases.  Files.  Object-Oriented Databases.  Object-Relational Databases.

JDBC Set of classes for interacting with a Relational Database. Implementation Neutral. The API is designed with the aim that code, once written can be run against several different database implementations (e.g. Oracle, PostGresQL) without modification. The reality is that true implementation neutrality is still difficult.

JDBC Abstract SQL in Java Program JDBC Driver Vendor Specific Execution of Java SQL Ansi SQLVendor’s SQL SQL ResultSet Java-Friendly ResultSet

JDBC-Key terms Connection. An authorized connection between a Java Program or servlet and a running database. Driver. Software object to take JDBC API calls from a Java program or servlet, translate it appropriately for the specific database, then pass it on to that database.

JDBC-Key terms Query. A statement that requests a Result Set from a database. It does NOT change the state of the database.  SELECT Update. A statement that potentially changes the state of the database. It may be any of the following:  DELETE  INSERT  UPDATE  DROP  Others

Overview of Database Processing using JDBC 1. Load Database Driver (once). 2. Establish a Connection to database from program (usually once but not always). 3. Create a Statement object to enable actions against the database. 1. Execute Queries using executeQuery() (repetitively). Process the ResultSet for each executeQuery(). 2. AND/OR 3. Execute Updates using executeUpdate() (repetitively). Return result of executeUpdate() should be tested and responded to.

Establishing a Connection: PreRequisites. The database engine you are connecting to is running. The program or servlet connecting to the database has access rights to that database. The driver, which is a java class file or jar file, is accessible to either the application, applet or servlet.

Establishing a Connection: Technique Dynamically Load the driver class using Class.forName. Driver must be available on CLASSPATH or in the case of servlets in the common/lib folder. Attempt to get a connection by calling the getConnection method of the DriverManager class. Always handle a failure to connect.

Establishing a Connection: Technique //Load driver class by package name then create instance Class.forName("com.mysql.jdbc.Driver").newInstance(); String url = "jdbc:mysql://localhost:3306/RentalDatabase"; // Connect using a url, a username without password con = DriverManager.getConnection(url, "RentalApp", "rentcars");

Statements Create a Statement object to execute an SQL command. Statement stmt = con.createStatement(); Use the executeUpdate() to execute a delete, drop, insert, or update (and other SQL commands that change the state of the database). Use the executeQuery() method to execute a select.

Statements ResultSet rs = state.executeQuery(“Select * from TableName”); Create a Statement object to execute an SQL command. Statement stmt = con.createStatement(); Use the executeUpdate() to execute a delete, drop, insert, or update (and other SQL commands that change the state of the database). Use the executeQuery() method to execute a select.

Processing ResultSets A query returns 0 or more rows of into a ResultSet. ResultSet rs = stmt.executeQuery(“Select * from TableName”); You iterate through the results in a result set using the next() method processing the data 1 row at a time. while (rs.next()) { // do something with current row. } Close the result set using close() rs.close();

Processing a Row in a ResultSet Rows returned during an iteration through a ResultSet contain fields. These fields must be converted into Java data types from the field type in the database. You can convert a field into a Java type by specifying either the Field Name or field number (if you know it) and choosing the conversion (getDouble,getInt, getString). while (rs.next()) { System.out.println(rs.getDouble(1)); System.out.println(rs.getString(“LastName”); System.out.println(rs.getInt(3)); } wasNull() tests whether the last conversion resulted in a null.