WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.

Slides:



Advertisements
Similar presentations
Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Advertisements

Database programming in Java An introduction to Java Database Connectivity (JDBC)
JDBC - Java Database Connectivity The objectives of this chapter are: To describe the architecture of JDBC To outline the classes in the java.sql package.
Distributed Application Development B. Ramamurthy.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 32 Java Database.
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.
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Dale Roberts 8/24/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
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.
JDBC Vs. Java Blend Presentation by Gopal Manchikanti Shivakumar Balasubramanyam.
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.
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.
Java Database Connectivity ASE. Java Database Connectivity (JDBC) l JDBC – provides an interface to Relational Data Sources l JDBC library provides the.
Database Programming in Java Corresponds with Chapter 32, 33.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
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  The JDBC (Java Database Connectivity) API helps a Java program to access a database in a standard way  JDBC is a specification that tells the.
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.
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.
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.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
JDBC Database Programming in Java Prepared by., Mrs.S.Amudha AP/SWE.
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.
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.
JDBC CHAPTER-2. JDBC - Java Database Connectivity. JDBC from Sun Microsystems provides API or Protocol to interact with different databases. With the.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
UNIT III - JDBC JDBC Overview – JDBC implementation – Connection class – Statements - Catching Database Results, handling database Queries. Networking–
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
Database Programming Contents 1. The Impedance Mismatch 2. JDBC 1. From the Ricardo text 2. From the Elmasri/Navathe text 3. From the ASU scholars 3. PLSQL:
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.
Basics of JDBC Session 14.
JDBC (Java Database Connectivity)
JDBC - Java Database Connectivity. JDBC provides Java applications with access to most database systems via SQL The architecture and API closely resemble.
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: Overview Contents 1. The Impedance Mismatch 2. JDBC 1. From the Elmasri/Navathe text 2. From the ASU scholars 3. PLSQL: by Prof.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
In the Name Of Almighty Allah. Java Application Connection To Mysql Created by Hasibullah (Sahibzada) Kabul Computer Science Faculty Afghanistan.
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.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
Interacting with Database
JDBC Database Management Database connectivity
CS320 Web and Internet Programming Database Access with JDBC
Advanced Web Automation Using Selenium
Introduction to Programming with Java
Objectives In this lesson, you will learn about:
Interacting with Database
JDBC – ODBC DRIVERS.
Java Database Connectivity
Java API for Database Connectivity
JDBC Example.
Presentation transcript:

WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars

WEB/DB2 ADVANCED DATABASE CONCEPTS JDBC Susan D. Urban and Suzanne W. Dietrich Department of Computer Science and Engineering Arizona State University Tempe, AZ

WEB/DB3 OPEN DATABASE CONNECTIVITY (ODBC) Standard application programming interface (API) for accessing a database. A separate module or driver is required for each database to be accessed. Based on the standard Call Level Interface (CLI) of the SQL Access Group (part of the X/Open Standard). Can use the API to execute SQL statements, update tables, and retrieve metadata.

WEB/DB4 ODBC ISSUES IN A JAVA ENVIRONMENT ODBC uses C to access the data source. This poses issues with implementation. Hence, it cannot be used in conjunction with Java. OBDC’S API cannot be used by translating the API to Java since there is no pointer concept in Java. ODBC requires the driver manager to be installed on every client installation.

WEB/DB5 JAVA DATABASE CONNECTIVITY (JDBC) Java API for connecting programs written in Java to databases. Based on ODBC. Allows Java programs to send SQL statements to any relational database. Platform independent. JDBC drivers written in Java can be accessed from any computer in a heterogeneous network. A JDBC-ODBC bridge can be used to access databases using the ODBC interface.

WEB/DB6 TWO-TIER JDBC ARCHITECTURES Java application or applet talks directly to the data source. Client sends requests to the server through user interfaces. JDBC Driver communicates with the data source to access the data. Sun Microsystems Inc. 1999

WEB/DB7 THREE-TIER JDBC ARCHITECTURES Uses a third tier between the client and the server. Controls updates that are made to the database. Secure and robust. Sun Microsystems Inc. 1999

WEB/DB8 DEVELOPING JDBC APPLICATIONS Import JDBC classes (java.sql.*) Load the JDBC Driver. Connect to the database. Use the JDBC API to access the database. Disconnect from the database.

WEB/DB9 ESTABLISHING A CONNECTION TO A DATABASE The first step in accessing data from any relational database using JDBC is to establish a connection with the data source. The Connection object is used to get meta data and execute SQL statements. The getConnection method returns a Connection object that represents a session with a specific database. The parameters in the getConnection method are URL, username and password. Username and password are optional. The URL consists of the protocol “jdbc”, sub-protocol “odbc”, and the Data Source Name (DSN).

WEB/DB10 EXAMPLE TO CONNECT TO A DATABASE /* dbName is the registered name of the ODBC data source */ String url = "jdbc:odbc:" + dbName ; try { /* Load the jdbc-odbc driver */ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); /* Open a connection to the odbc data source */ con =DriverManager.getConnection(url,"",""); }

WEB/DB11 STATEMENTS A Statement Object is used to send SQL queries to a database. A Statement object should be created using the connection method createStatement().

WEB/DB12 TYPES OF STATEMENTS There are three types of statement objects: Simple statements Used to execute SQL statements without any parameters. Statement stmt = connection.createStatement(); Prepared Statements Used when a statement will be called several times and is stored as a pre-compiled statement with IN parameters. PreparedStatement pstmt = con.prepareStatement(“update employee set salary=? where ssn=?”); Callable Statements Used with calls to database stored procedures and SQL statements with OUT parameters.

WEB/DB13 EXECUTING SIMPLE STATEMENTS The execution of a statement returns results into a ResultSet object. The ResultSet object is then used to access query results. ResultSet rs = null; The executeQuery() method is used to execute an SQL statement through the statement object. rs = stmt.executeQuery("SELECT a, b, c FROM Table1"); The close() method is used to close the ResultSet. rs.close();

WEB/DB14 GETTING DATA FROM A ResultSet The next() method is used to traverse through tuples in the ResultSet object. The data stored in a ResultSet object is retrieved through a set of get methods that allows access to the various columns of the current row. The results are printed out on a screen using the Servlet output stream. while(rs.next()) { out.println(rs.getString(“SSN”)); }

WEB/DB15 DATABASE METADATA Metadata is the information in the database that is associated with the database schema: Table names Column names Column types The metadata associated with a database can be queried using JDBC. The metadata associated with the result set object of a statement execution can also be queried.

WEB/DB16 DATABASE METADATA RETRIEVAL Create a metadata object. DatabaseMetaData dbmd ; Retrieve metadata from the database through the connection established. dbmd = con.getMetaData(); The getTables() method of the metadata object is used to retrieve information about the tables in a database. The information is stored in a result set object. ResultSet rsTables = dbmd.getTables(null, null, null, null);

WEB/DB17 GETTING THE METADATA The getString() method of the ResultSet object is used to locate a specific table. String tableName = rsTables.getString("TABLE_NAME"); The getColumns() method is used to retrieve information about the columns and column types in a table, with the results stored in a ResultSet object. ResultSet rsColumns = dbmd.getColumns(null,null,tableName,null); while (rsColumns.next()) { … }