SlideShare una empresa de Scribd logo
1 de 10
2.1 JAVA DATABASE
CONNECTIVITY (JDBC)
2.1.1 JDBC AND ODBC DATABASE
ACCESS
Java Database Connectivity (JDBC) Open Database Connectivity
(ODBC)
• is the trademark name of a Java
API that supports java program
that access relational databases.
• Using JDBC you can send SQL,
PL/SQL statements to almost
any relational databases.
• JDBC is a Java API for executing
SQL statements and supports
basic SQL functionality.
• It provides methods for querying
and updating data in a database.
• is a standard programming
language middleware API for
accessing database management
systems (DBMS).
• The designers of ODBC aimed to
make it independent of database
systems and operating systems.
• An application written using
ODBC can be ported to other
platforms, both on the client
and server side, with few
changes to the data access code.
2.1.2 JDBC DRIVER TYPES
JDBC technology drivers fit into one of four categories.
1) JDBC-ODBC bridge
2) Native-API Driver
3) Network-Protocol Driver(MiddleWare Driver)
4) Database-Protocol Driver(Pure Java Driver)
Type 1 : JDBC-
ODBC bridge
Type 2 : Native-API
Driver
Type 3 : Network-
Protocol Driver
(MiddleWare Driver)
Type 4 : Database-
Protocol Driver
(Pure Java Driver)
• used to access
ODBC drivers
installed on each
client machine.
• Using ODBC
requires
configuring on
your system a
Data Source
Name (DSN) that
represents the
target database.
• JDBC API calls are
converted into
native C/C++ API
calls which are
unique to the
database.
• . These drivers
typically provided
by the database
vendors and used
in the same
manner as the
JDBC-ODBC
Bridge, the
vendor-specific
driver must be
• a three-tier
approach is used
to accessing
databases.
• The JDBC clients
use standard
network sockets
to communicate
with an
middleware
application
server.
• communicates
directly with
vendor's
database through
socket
connection.
• This is the
highest
performance
driver available
for the database
and is usually
provided by the
vendor itself.
2.1.3 JDBC STATEMENT OBJECTS
INTERFACES RECOMMENDED USE
Statement Use for general-purpose access to your database.
Useful when you are using static SQL statements at
runtime. The Statement interface cannot accept
parameters.
Prepare Statement Use when you plan to use the SQL statements
many times. The PreparedStatement interface
accepts input parameters at runtime.
Callable Statement Use when you want to access database stored
procedures. The CallableStatement interface can
also accept runtime input parameters.
2.1.4 STEP INVOLVE IN JDBC
a) Load the driver
b) Define the connection
c) Establish the connection
d) Create a statement object
e) Execute a query
f) Process the result
g) Close the connection
1. Loading Drivers
Class.forName(“JDBCDriverClass”);
Database Driver Class Source
Ms Access sun.jdbc.odbc.JdbcOdbcDriver Already in JDK
MySQL com.mysql.jdbc.Driver Companion Website
Oracle oracle.jdbc.driver.OracleDriver Companion Website
2. Establishing connections
Connection con = DriverManager.getConnection(databaseURL);
Database URL Pattern Example
Ms Access jdbc:odbc:dataSource
Connection connection =
DriverManager.getConnection(“jdbc:od
bc:DatabaseSaya”);
MySQL jdbc:mysql://hostname/dbname
Connection connection =
DriverManager.getConnection(“jdbc:m
ysql://localhost/Data baseSaya”);
Oracle
jdbc:oracle:thin:@hostname:
port#:oracleDBSID
Connection connection =
DriverManager.getConnection(“jdbc:or
acle:thin:@hawariyah.
psp.edu.my:1521:ora91”,”hawariyah”,”
psp”);
3. Creating Statements
Statement stmt = con.createStatement();
4. Executing statements
//untuk create table baru/update data dalam table
stmt.executeUpdate(“SQL statement”);
//utk papar data dalam table
stmt.executeQuery(“SQL statement”);
Example :
ResultSet rs = stmt.executeQuery
(“SELECT firstname,lastname FROM student WHERE lastname” + “=
‘smith’ “);
5. Process the result
// Iterate through the result and print the student names
while (rs.next())
System.out.println (rs.getString(1) + “ “ + rs.getString(2) + “ “ +
rs.getString(3));
6. Close connection to database
Close the ResultSet object
 rs.close();
Close the Statement object
 stmt.close();
Close the connection
 conn.close();

Más contenido relacionado

La actualidad más candente

DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase Connectivity
Akankshaji
 

La actualidad más candente (20)

Lecture 1. java database connectivity
Lecture 1. java database connectivityLecture 1. java database connectivity
Lecture 1. java database connectivity
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
 
Database Access With JDBC
Database Access With JDBCDatabase Access With JDBC
Database Access With JDBC
 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
 
Jdbc
JdbcJdbc
Jdbc
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
Jdbc connectivity in java
Jdbc connectivity in javaJdbc connectivity in java
Jdbc connectivity in java
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
 
JDBC
JDBCJDBC
JDBC
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase Connectivity
 
Overview Of JDBC
Overview Of JDBCOverview Of JDBC
Overview Of JDBC
 
JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Jdbc complete
Jdbc completeJdbc complete
Jdbc complete
 
JDBC
JDBCJDBC
JDBC
 

Similar a 1. java database connectivity (jdbc)

JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.ppt
kingkolju
 
jdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxjdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptx
ssuser8878c1
 

Similar a 1. java database connectivity (jdbc) (20)

java 4 Part 1 computer science.pptx
java 4 Part 1 computer science.pptxjava 4 Part 1 computer science.pptx
java 4 Part 1 computer science.pptx
 
jdbc
jdbcjdbc
jdbc
 
Jdbc introduction
Jdbc introductionJdbc introduction
Jdbc introduction
 
JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.ppt
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Unit 5.pdf
Unit 5.pdfUnit 5.pdf
Unit 5.pdf
 
Unit 5-jdbc2
Unit 5-jdbc2Unit 5-jdbc2
Unit 5-jdbc2
 
Jdbc
JdbcJdbc
Jdbc
 
3 jdbc
3 jdbc3 jdbc
3 jdbc
 
java.pptx
java.pptxjava.pptx
java.pptx
 
Jdbc 1
Jdbc 1Jdbc 1
Jdbc 1
 
jdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxjdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptx
 
Core jdbc basics
Core jdbc basicsCore jdbc basics
Core jdbc basics
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptx
 
jdbc
jdbcjdbc
jdbc
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
 
Chapter_4_-_JDBC[1].pptx
Chapter_4_-_JDBC[1].pptxChapter_4_-_JDBC[1].pptx
Chapter_4_-_JDBC[1].pptx
 

Último

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Último (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

1. java database connectivity (jdbc)

  • 2. 2.1.1 JDBC AND ODBC DATABASE ACCESS Java Database Connectivity (JDBC) Open Database Connectivity (ODBC) • is the trademark name of a Java API that supports java program that access relational databases. • Using JDBC you can send SQL, PL/SQL statements to almost any relational databases. • JDBC is a Java API for executing SQL statements and supports basic SQL functionality. • It provides methods for querying and updating data in a database. • is a standard programming language middleware API for accessing database management systems (DBMS). • The designers of ODBC aimed to make it independent of database systems and operating systems. • An application written using ODBC can be ported to other platforms, both on the client and server side, with few changes to the data access code.
  • 3. 2.1.2 JDBC DRIVER TYPES JDBC technology drivers fit into one of four categories. 1) JDBC-ODBC bridge 2) Native-API Driver 3) Network-Protocol Driver(MiddleWare Driver) 4) Database-Protocol Driver(Pure Java Driver)
  • 4. Type 1 : JDBC- ODBC bridge Type 2 : Native-API Driver Type 3 : Network- Protocol Driver (MiddleWare Driver) Type 4 : Database- Protocol Driver (Pure Java Driver) • used to access ODBC drivers installed on each client machine. • Using ODBC requires configuring on your system a Data Source Name (DSN) that represents the target database. • JDBC API calls are converted into native C/C++ API calls which are unique to the database. • . These drivers typically provided by the database vendors and used in the same manner as the JDBC-ODBC Bridge, the vendor-specific driver must be • a three-tier approach is used to accessing databases. • The JDBC clients use standard network sockets to communicate with an middleware application server. • communicates directly with vendor's database through socket connection. • This is the highest performance driver available for the database and is usually provided by the vendor itself.
  • 5. 2.1.3 JDBC STATEMENT OBJECTS INTERFACES RECOMMENDED USE Statement Use for general-purpose access to your database. Useful when you are using static SQL statements at runtime. The Statement interface cannot accept parameters. Prepare Statement Use when you plan to use the SQL statements many times. The PreparedStatement interface accepts input parameters at runtime. Callable Statement Use when you want to access database stored procedures. The CallableStatement interface can also accept runtime input parameters.
  • 6. 2.1.4 STEP INVOLVE IN JDBC a) Load the driver b) Define the connection c) Establish the connection d) Create a statement object e) Execute a query f) Process the result g) Close the connection
  • 7. 1. Loading Drivers Class.forName(“JDBCDriverClass”); Database Driver Class Source Ms Access sun.jdbc.odbc.JdbcOdbcDriver Already in JDK MySQL com.mysql.jdbc.Driver Companion Website Oracle oracle.jdbc.driver.OracleDriver Companion Website
  • 8. 2. Establishing connections Connection con = DriverManager.getConnection(databaseURL); Database URL Pattern Example Ms Access jdbc:odbc:dataSource Connection connection = DriverManager.getConnection(“jdbc:od bc:DatabaseSaya”); MySQL jdbc:mysql://hostname/dbname Connection connection = DriverManager.getConnection(“jdbc:m ysql://localhost/Data baseSaya”); Oracle jdbc:oracle:thin:@hostname: port#:oracleDBSID Connection connection = DriverManager.getConnection(“jdbc:or acle:thin:@hawariyah. psp.edu.my:1521:ora91”,”hawariyah”,” psp”);
  • 9. 3. Creating Statements Statement stmt = con.createStatement(); 4. Executing statements //untuk create table baru/update data dalam table stmt.executeUpdate(“SQL statement”); //utk papar data dalam table stmt.executeQuery(“SQL statement”); Example : ResultSet rs = stmt.executeQuery (“SELECT firstname,lastname FROM student WHERE lastname” + “= ‘smith’ “);
  • 10. 5. Process the result // Iterate through the result and print the student names while (rs.next()) System.out.println (rs.getString(1) + “ “ + rs.getString(2) + “ “ + rs.getString(3)); 6. Close connection to database Close the ResultSet object  rs.close(); Close the Statement object  stmt.close(); Close the connection  conn.close();