database connectivity to mysql. introduction =>a real life application needs to manipulate data...

25
DATABASE CONNECTIVITY TO MYSQL

Upload: clifton-hopkins

Post on 17-Jan-2016

295 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of

DATABASE CONNECTIVITY TO MYSQL

Page 2: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of

Introduction

=>A real life application needs to manipulate data stored in a Database.

=>A database is a collection of related data in the form of Tables. Most of the database uses SQL (Structured Query Language) to Insert, Delete, Update or retrieve stored data.

=>In order to connect a Java application to a database designed in MySQL, Oracle, Sybase, MS SQL Server etc, you need a Bridge/Interface Driver Program.

=>Java Provides JDBC (Java Database Connection) and JDBC-ODBC interface/ Driver to connect a database. JDBC is commonly used to connect MySQL database.

Page 3: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of

=>What is JDBC ?JDBC is JAVA’s Database connection

driver interface which performs the following task for the application.

(1).Establish a connection with a Database.(2).Send SQL request (Query) to a Database

Server.(3.Returns Result obtained against Query.Some RDBMS like MS Access requires

ODBC (Open Database Connection), which can be connect through JDBC-ODBC driver(jdbc.odbcbridge).

Page 4: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 5: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of

Classes used for Database ConnectivityThe Core element of JDBC is JDBC API, which consists

of a set of Java classes equipped with predefined methods to handle various data access functions such as Selecting appropriate database driver, establishing connection, submitting SQL query and processing results.

There are four main classes in the JDBC.1.Driver Manager Class : The JDBC Driver Manager

Class Loads the JDBC driver needed to access a particular data source, locates & logs on to the database & returns a Connection Objects.

2.Connection Class : The JDBC Connection class manages the communications between a java client application & a specific database (e.g. MYSQL database), including passing SQL statement to the DBMS & managing transactions.

Page 6: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of

=>3.Statement Class : The JDBC Statement class contains SQL string that are submitted to the DBMS .An SQL Select statement returns a result Set object that contains the data retreived as the result of SQL statement.

=>4.Result set class: The JDBC Result Set class provides predefined methods to access, analyze,& convert data values returned by an executed SQL select statement.

A JDBC driver must be registered with JDBC Driver Manage using Class.forName() method before establishing a connection.

Page 7: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of

CONNECTIVITY TO MYSQL FROM JAVASteps for creating Database Connectivity

Applications

There are mainly six steps :Step1: Import the packages Required for

Database Programming.Step2: Register the JDBC Driver to JDBC

Driver managerStep3: Open a connectionStep4: Execute a QueryStep5: Extract Data From Result setStep6: Close Connection.

Page 8: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of

=> Connection: A connection(represented through connection object) is the session between the application program and the database .to do anything with database, one must have a connection object.

=>Result Set: A Result set (represent by a Result Set Object) refers to a logical set of records that are fetched from the database by executing a query and made avalible to the application-program.

Page 9: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 10: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 11: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 12: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 13: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 14: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 15: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 16: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 17: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 18: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 19: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 20: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 21: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 22: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 23: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 24: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of
Page 25: DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of