0% found this document useful (0 votes)
41 views4 pages

JDBC 1

The document discusses technologies used in advanced Java projects including SQL, JDBC, servlets, JSP, HTML, CSS, and JavaScript. It then provides details on JDBC, the different types of JDBC drivers, and the steps to write a JDBC application: 1) import java.sql package, 2) register the JDBC driver class, 3) open a connection, 4) create a Statement object, 5) execute SQL statements using executeUpdate() or executeQuery(), 6) process results, and 7) optionally close the connection. It also provides examples of connecting to Oracle and MySQL databases using JDBC.

Uploaded by

ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views4 pages

JDBC 1

The document discusses technologies used in advanced Java projects including SQL, JDBC, servlets, JSP, HTML, CSS, and JavaScript. It then provides details on JDBC, the different types of JDBC drivers, and the steps to write a JDBC application: 1) import java.sql package, 2) register the JDBC driver class, 3) open a connection, 4) create a Statement object, 5) execute SQL statements using executeUpdate() or executeQuery(), 6) process results, and 7) optionally close the connection. It also provides examples of connecting to Oracle and MySQL databases using JDBC.

Uploaded by

ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Technologies in the Advanced Java Projects

===========================================
SQL
JDBC
Servlets
JSP

HTML
CSS
JavaScript

JDBC (Java Database Connectivity)

JDBC is a software abstraction which is used to access any types of Relational


Databases.
It sits between java application and the database we want to access.

Java Application------->JDBC------->Database (MySql,Oracle,SQL Server,DB2 etc)

JDBC gives an uniform approach to access any type of database.

JDBC Drivers
============
Database is stored in its own format. No computer program can directly access them.

Microsoft came up ODBC technology (Open Database Connectivity). Can be used to


access
any type of database.

ODBC technology is developed using C language. Extensively uses the concept of


pointers.
ODBC directly cannot be used in Java.

Javasoft developed a set of API to interact with ODBC drivers. They are called JDBC
drivers

Java Application------->JDBC------->ODBC---->Database (MySql,Oracle,SQL Server,DB2


etc)

JDBC-ODBC Bridge

JDBC Drivers
==============
JDBC-ODBC Bridge Driver (Type-I)
Native API Driver (Type-II)
Network Protocol Driver (Type-III)
Native Protocol Driver (Type-IV)

Java 8 and above versions do not support type-I driver.

ODBC is developed in C. C is not platform independent.


native
protocol
Java Application--------->Type IV Driver ---->Database

Thin Driver

Writing a JDBC Application


==========================
1) Import the java.sql package (import java.sql.*)
import java.sql.Connection;
import java.sql.DriverManager;
...............
...............

2) Register the driver


Class.forName("driver_class_name");

Registering the Oracle Driver


Class.forName("oracle.jdbc.driver.OracleDriver");

oracle->main package
jdbc->sub package
driver->sub sub package
OracleDriver->class name

Registering to mysql
Class.forName("com.mysql.jdbc.Driver");

com.mysql.cj.jdbc.Driver

3) Opening of Connection
=====================
To open connection, the connection object is linked with DriverManager class.

Connection con=DriverManager.getConnection("jdbc_url","user_name","password");

To Connect to Oracle
=====================
In oracle instead of database, users are created.
Create user user_name identified by password;
grant all privileges to user_name;
connect user_name/password;

Create table.....

Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521","user","pwd");

jdbc ->Main protocol


oracle->sub protocol
thin->DriverName
1521->port

MySQL
======
Create database data_base;
use database;
Create table.....
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/database","user","pwd"
);

4) Create the Statement object

Statment stmt=con.createStatement();

5) Execute the SQL statement


=============================
DML(Data Manipulation) DRL (Data Retrival)
======================= ===================
Insert, Update, Delete Select
Do not return any Resultset Returns a ResultSet
executeUpdate() method is used to executeQuery() is used to run

execute these statement run the select statement

6) Process the results

7) Close the connection (optional)


con.close();

You might also like