Chapter 9 Database Connectivity
Chapter 9 Database Connectivity
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.
What is JDBC ?
JDBC is JAVAs Database connection driver
interface which performs the following task for
the application.
Establish a connection with a Database.
Send SQL request (Query) to a Database
Server.
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).
Architecture of JDBC
JAVA Application
JDBC API
JDBC Driver
Database
2. Press
Add
JAR/Folder
java.sql.Statement;
Or
import java.sql.*;
import java.sql.ResultSet;
int r= rs.getInt(1);
String n= rs.getString(name);
String n= rs.getString(2);
int c= rs.getInt(class);
int c= rs.getInt(3);
Purpose
next ()
Moves the cursor forward one row. It returns false when cursor is
positioned after the last record.
previous()
first()
last()
relative(n)
obsolute(n)
getRow()
BtnDisp
[Jbutton]
BtnExit [Jbutton]
JTextField (s) as
TxtRoll, TxtName &
TxtClass
JButtons as
BtnFirst,
BtnPrev,
BtnNext, BtnLast &
BtnExit
Ensure the
JDBC driver
is present in
the library
The following Swing Controls are
attached ( Name and Types)
Connection is
established
and cursor is
placed on first
record when
Frame loads.
Coding for
LAST button to
locate and
display last
record
Coding for
EXIT button
to close
connection
environment
and Exit from
application.