0% found this document useful (0 votes)
0 views

Database Connection With Javascript

The document provides an overview of connecting databases with Java using JDBC, detailing its history, definition, architecture, and types of JDBC drivers. It outlines the steps required to connect a Java application to a database, including registering the driver, creating a connection, executing queries, and closing the connection. Additionally, it discusses the limitations of the ODBC model compared to JDBC.

Uploaded by

mkkrockstars
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Database Connection With Javascript

The document provides an overview of connecting databases with Java using JDBC, detailing its history, definition, architecture, and types of JDBC drivers. It outlines the steps required to connect a Java application to a database, including registering the driver, creating a connection, executing queries, and closing the connection. Additionally, it discusses the limitations of the ODBC model compared to JDBC.

Uploaded by

mkkrockstars
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Database

Connection with
Javascript

BY
JACK JAYARAJ J
&
KISHORE
KUMAR M
Topics
 HISTORY
 DATABASE
 JDBC DEFINITION
 ARCHITECTURE OF JDBC
 JDBC DRIVER TYPES
 WHY NOT SYMPLY ADOPT ODBC MODEL ?
 STEPS TO CONNECT JAVA APP. WITH DATABASE
HISTORY
 Early days, data was first stored in file systems , which made it
challenging to organize and retrieve information efficiently.
 In 1960, researchers started developing electronic systems to store and
manage data.
 One of the earliest database model was hierarchial model, which
organized data in a tree-like structure.
 In 1970, The real breakthrough came with the invention of the relational
database model by Edgar Codd .
 This model introduced the concept of tables, rows, &coloumns.
 In 1980 & 1990, object-oriented databases gained attention, allowing for
more complex data modelling & handling.
DATABASE
A database is structured collection of data that is
organized, stored, and managed in a computer
system .
 It allows you to store & retrieve information efficiently
.
 It’s
a digital filing system where you can store and
organize data in tables, rows, & columns .
 Databases are commonly used in various applications
. such as websites, mobile apps & business systems,
to store & manage large amounts of data .
JDBC DEFINITION
 Java Database Connectivity.
 It is an interface between Java & Database .
 Itreceives queries from Java Application program &
communicate with Database.
 All
the communications are in the form of SQL
commands.
Architecture of
JDBC
JDBC DRIVER TYPES
1. JDBC-ODBC Bridge Driver
2. Native API Partly Java
Driver
3. Network Protocol Driver
4. Thin Driver
1) JDBC-ODBC Bridge
Driver
 This Driver acts as a bridge between the
JDBC API & the ODBC (Open Database
Connectivity) API.
 Itrequires the installation of ODBC driver
on the client side machine.
 Itis platform dependent and may have
limited functionality & performance.
2) Native API Partly Java
Driver
 ThisDriver uses the database’s native API to
establish a connection .
 It converts JDBC method calls into native API calls.
 Itprovides better performance compared to type
1 Driver.
 It requires the installation of the database-specific
client library on the client machine.
 Platform-Dependent & may have limited
portability.
3) Network Protocol
Driver

This driver uses a network protocol to
communicate with a server-side application .
 It converts JDBC method calls into a protocol-
specific message format .
 It does not requires the installation of any
database-specific client library on the client
machine .
 It provides better portability and allows
connectivity to multiple databases .
4) Thin Driver
(Direct Protocol Driver)
 The driver communicates directly with the database
server using a database-specific protocol.
 It does not require any additional software installation on
the client machine.
 It provides the best performance & portability among all
driver types.
 It is platform-independent & can connect to multiple
databases .
 It is the most commonly used driver type in modern JDBC
applications .
Why not simply adopt
ODBC model?
it is written in c language .
ODBC is hard to learn .
It has few commands with lot of
complex options .
ODBC solution is inherently less safe .
It’s not portable language as platform
dependent .
5 Steps to Connect Java
App. With Database
using JDBC
1) Register the driver class
* For using SQL, import.java.sql
• forName( )method
• used to register the driver class.
* This function loads the driver and
activates it .
2) Create connection
 getConnection( ) method
 Establish the connection between registered
driver and database.
 Two Functions ,
 1)Public Static Connection
getconnection(string URL)
 2) Public Static Connection
getconnection(string URL,username,password)
3) Create the statement
object
CreateStatement( ) method
 Through this we execute the query with the
object .

4) Execute the Query


 EcecuteQuery( ) method
 With created statement object , we are going
to execute the query.
* In database we are creating a table ,and writing
queries in executie queries to insert or update data.

5)Close the connection


Close( ) method
Closes the database and programing language
driver registered ,loaded and would establish a
connection.
We are closing the connection for security .
Sample program
Import java.sql,*;
Class MysqlCon
{
Public static void main( string args[])
try{
Class.forName(“com.mysql.Jdbc.Driver”);
Connection con=Driver
Manager.grtconnnection(“jdbc:mysql://localhost:3306/hemajdbc”, “root”,” “);
stament stmt=con,createStatement());
ResultSet rs=stmt.executeQuery(“select*from emp”);whilers,next()
System.out.printIn(rs.getInt(1)+” “+rs.getSting(2)+” “+rs.getString(3));
Con.close();
}catch(Exception e){system.out.printIn(e);}
}
}

You might also like