EntJava_JavaDatabaseConnectivity

Views:
 
Category: Entertainment
     
 

Presentation Description

No description available.

Comments

Presentation Transcript

Java Database Connectivity : 

Java Database Connectivity

What is JDBC? : 

What is JDBC? Java Database Connectivity in short called as JDBC It is a java API which enables the java programs to execute SQL statements It is an application programming interface that defines how a java programmer can access the   database in tabular format from Java code using a set of  standard interfaces and classes written in the Java programming language

What is JDBC? : 

What is JDBC? The Java application programming interface provides a mechanism for dynamically loading the correct Java packages and drivers and registering them with  the JDBC Driver Manager that is used as a connection factory for creating JDBC connections which supports creating and executing statements such as SQL INSERT, UPDATE and DELETE. Driver Manager is the backbone of the jdbc architecture

Purpose of JDBC : 

Purpose of JDBC It helps us to connect to a data source, like a database It helps us in sending queries and updating statements to the database Retrieving and processing  the results received from the database in terms of answering to your query

JDBC Components : 

JDBC Components The JDBC API The JDBC Driver Manager The JDBC Test Suite The JDBC-ODBC Bridge

The JDBC API : 

The JDBC API The JDBC application programming interface provides the facility for  accessing  the relational database from the Java programming language The user not only execute the SQL statements, retrieve results, and update the data but can also access it  anywhere within a network because of  it's "Write Once, Run Anywhere" (WORA) capabilities

Interfaces of JDBC API : 

Interfaces of JDBC API The latest version of  JDBC 4.0 application programming interface is divided into two packagesi-) java.sqlii-) javax.sql.  Java SE and Java EE platforms are included in both the packages.

The JDBC Driver Manager : 

The JDBC Driver Manager The JDBC Driver Manager is a very important class that defines objects which connect Java applications to a JDBC driver JDBC database driver loads all drivers found in the system properly as well as to select the most  appropriate driver from opening a connection to a database The Driver Manager helps to select the most appropriate driver from the previously loaded drivers when a new open database is connected

The JDBC Test Suite : 

The JDBC Test Suite The function of  JDBC driver test suite is to make ensure that the  JDBC drivers will run user's program or not The test suite of  JDBC application program interface is very useful  for testing a driver based on JDBC technology during testing period

The JDBC-ODBC Bridge : 

The JDBC-ODBC Bridge JDBC type 1 driver is a  database driver that utilize the ODBC driver to connect  the  database This driver translates JDBC method calls into ODBC function calls The Bridge implements JDBC for any database for which an ODBC driver is available The Bridge is always implemented as the sun.jdbc.odbc Java package and it contains a native library used to access ODBC

JDBC Connection : 

JDBC Connection Before the implementation of class we need to import a package java.sql.* needed for network interface between url and back end Loading a driver is done by calling a class.forName ( ) and accept the driver class as argument

JDBC Connection : 

JDBC Connection DriverManager.getConnection  ( ) :This method returns you an connection object.DriverManager.getConnection built a connection with database con.close ( ) : An object of connection is used to close the connection between database and url

Connection Example : 

Connection Example Click on Connection Example in Moodle

JDBC access database : 

JDBC access database Gathering Resources - import a package import java.sql.*;This package import the list of all classes defined in java.sql.*. Database Driver Loading - load the driver class by invoking Class.forName( ) with the Driver class name passed as an argument

JDBC access database : 

JDBC access database st = con.createconnection( ) -Used to create Sql object. Once a connection is established ,you can interact with backend database A connection object is used to send and execute SQL Statement to a backend database

JDBC access database : 

JDBC access database rs = st.executequery(sql) - Used to for select query in sql and the value retrieved from it stored in  result set rs The Result Set enables you to access a table containing data next( ) - Used to retrieve successively element through the rows obtained from a result set

Database Connection Example : 

Database Connection Example Click on Database Connection Example in Moodle

Exercise : 

Exercise With sample programs provided. Create a web application that uses JSP for interface and Servlet for the program logic and bridge to the database. Web application should be able retrieve data from the database and display in a JSP page. Take note that Servlet must be the bridge from the Back End to the Front End