SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
by Tanmoy Barman
cont:- barmantanmoy.47@gmail.com
Discussions
 What?
 Architecture of JDBC.
 Types of JDBC driver available.
 Steps to connect to DB.
 Types of Statement.
 JDBC Data Source.
What is JDBC ?
 JDBC acronym of java Database
connectivity; though Sun Microsystems
claims that it is not the full form.
 JDBC is a standard java API for
independent database connection between a
java program and wide range of relational
database.
 It is present in the “java.sql” package
Architecture of JDBC
Types of JDBC driver
 Type 1; jdbc-odbc bridge driver
 Type 2; native API partly java driver.
 Type 3; net protocols all java driver.
 Type 4; native protocols all java driver.
Steps to connect?
 Define the connection URL.
 Established the connection.
 Create the Statement object.
 Execute a query.
 Process the results.
 Close the connection.
Steps to connect?
 Define the connection url :
Class.forName();
 For jdbc-odbc bridge driver:-
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
 For oracle driver:-
Class.forName(“oracle.jdbc.driver.OracleDriver”);
 For My sql driver:-
Class.forName(“com.mysql.jdbc.Driver”);
Steps to connect?
 Established the connection:
Connection con
=DriverManager.getConnection(“url”,”user_name”,”pass”);
Steps to connect?
 Create the Statement object:
Statement stmt=con.createStatement();
Steps to connect?
 Execute the query:
 For the SELECT query:-
 String sql=“SELECT * FROM EMP”;
 stmt.executeQuery(sql);
 For the INSERT/UPDATE query:-
 String sql=“INSERT INTO EMP VALUES(47,’TEDDY’)”;
 stmt.executeUpdate(sql);
Steps to connect?
 Process the result:-
ResultSet rs=stmt.execute Query(sql);
while(rs.next()){
System.out.println(rs.getInt(id));
System.out.print(rs.getString(name));
}
Steps to connect?
 Close the connection
release all the resources that the connection
is holding.
stmt.close();
con.close();
Steps to connect?
 Summarizing the steps for connecting java DB and inserting values in
DB, deployed on Net Beans IDE :-
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection
con=DriverManager.getConnection("jdbc:derby://localhost:1527/orbacus","teddy","teddy");
Statement stmt=con.createStatement();
String sql=“INSERT INTO TEDDY(47,’jani’)”;
stmt.executeUpdate(sql);
stmt.close();
con.close();
Types of Statement available
 There are three types of Statement
available in Statement class:-
 Statement
 PreparedStatement
 CallableStatement
Types of Statement available
 Statement
This represent a simple sql/mysql
statement.
Statement stmt=con.createStatement();
Types of Statement available
 PreparedStatement
this represent precompiled sql/my sql
statement which allows improved
performance. It allows to execute the query
multiple times and we can set the values
according to our need.
PreparedStatement psmt=con.prepareStatement();
Types of Statement available
 CallableStatement
This allows the access of stored
procedures; that are stored on the database.
CallableStatement csmt=con.prepareCall();
JDBC Data Source
 The JDBC data source interface is an
alternative to DriverManager class and
conventional JBDC url. All the database
information is present in the Naming
service and retrieved using the JNDI API.
The Data Source object contains the
connection information which will make the
actual connection and execute the JDBC
commands.
JDBC Data Source:
 Each Data Source is assigned a logical name
by conventional beginning with jdbc/ .
 Advantages:-
○ Makes the code portable and reuse.
○ The application does not have to remember the
hardcore driver information.
○ Connection pooling and distributed transaction
advantages is facilitate.
JDBC Data Source:
 Syntax:-
Context ctx=new InitialContext();
DataSource
ds=(DataSource)ctx.lookup(“jdbc/teddyDB”);
Connection
con=ds.getConnection(“user_name”,”pass”);
Thank You

More Related Content

PPTX
Java swing
PPTX
oops concept in java | object oriented programming in java
PPTX
Types of Drivers in JDBC
PPTX
Servlets
PPTX
Introduction to Spring Framework
PPS
Java rmi
PPTX
Presentation on Core java
PPT
Java swing
oops concept in java | object oriented programming in java
Types of Drivers in JDBC
Servlets
Introduction to Spring Framework
Java rmi
Presentation on Core java

What's hot (20)

PPT
JDBC – Java Database Connectivity
PPT
Servlet life cycle
PPS
Jdbc architecture and driver types ppt
PDF
Servlet and servlet life cycle
PPT
JDBC Architecture and Drivers
PPT
Jsp ppt
PDF
Java threads
PPT
Java collections concept
PPTX
Core java complete ppt(note)
PPTX
Java Server Pages(jsp)
PPTX
Java Beans
PPT
Java Servlets
PPTX
JAVA AWT
PPTX
Inheritance in JAVA PPT
PPTX
Inheritance in java
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPSX
Javascript variables and datatypes
PPTX
Interface in java
PPTX
Method overloading
JDBC – Java Database Connectivity
Servlet life cycle
Jdbc architecture and driver types ppt
Servlet and servlet life cycle
JDBC Architecture and Drivers
Jsp ppt
Java threads
Java collections concept
Core java complete ppt(note)
Java Server Pages(jsp)
Java Beans
Java Servlets
JAVA AWT
Inheritance in JAVA PPT
Inheritance in java
Basic Concepts of OOPs (Object Oriented Programming in Java)
Javascript variables and datatypes
Interface in java
Method overloading
Ad

Viewers also liked (20)

PPT
JDBC Java Database Connectivity
PPT
JDBC Tutorial
PPT
Jdbc ppt
PPTX
Database Access With JDBC
PPS
Jdbc example program with access and MySql
PPT
Java Servlets
PPT
Java Database Connectivity
ODP
Java Collections
PPT
3 database-jdbc(1)
PPT
Java Server Pages
PPTX
Java database connectivity with MySql
PPTX
Java database connectivity with MySql
PPTX
Interface callable statement
PPTX
Java.sql package
KEY
JDBC Basics (In 20 Minutes Flat)
PPT
PPTX
JDBC ppt
JDBC Java Database Connectivity
JDBC Tutorial
Jdbc ppt
Database Access With JDBC
Jdbc example program with access and MySql
Java Servlets
Java Database Connectivity
Java Collections
3 database-jdbc(1)
Java Server Pages
Java database connectivity with MySql
Java database connectivity with MySql
Interface callable statement
Java.sql package
JDBC Basics (In 20 Minutes Flat)
JDBC ppt
Ad

Similar to JDBC: java DataBase connectivity (20)

PPTX
Jdbc
PPTX
Jdbc
DOC
PDF
Chapter 5 JDBC.pdf for stufent of computer andtudent It s
PDF
Introduction to JDBC and JDBC Drivers
PPTX
chapter 5 java.pptx
PDF
PPTX
Jdbc new
PPTX
Jdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbc
PPT
JDBC.ppt
PDF
java arlow jdbc tutorial(java programming tutorials)
PPTX
PPTX
Jdbc introduction
PPTX
jdbc-130913021409-phpapp01000988www.pptx
PPT
Basic Java Database Connectivity(JDBC)
PPT
11. jdbc
PPT
jdbc_presentation.ppt
Jdbc
Jdbc
Chapter 5 JDBC.pdf for stufent of computer andtudent It s
Introduction to JDBC and JDBC Drivers
chapter 5 java.pptx
Jdbc new
Jdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbc
JDBC.ppt
java arlow jdbc tutorial(java programming tutorials)
Jdbc introduction
jdbc-130913021409-phpapp01000988www.pptx
Basic Java Database Connectivity(JDBC)
11. jdbc
jdbc_presentation.ppt

More from Tanmoy Barman (7)

PPSX
Java rmi
PPSX
PPSX
Java server pages
PPTX
java Servlet technology
PPTX
Web apps architecture
DOCX
introduction to channel borrowing scheme in cellular networks
PPT
INTRODUCTION TO CLOUD COMPUTING
Java rmi
Java server pages
java Servlet technology
Web apps architecture
introduction to channel borrowing scheme in cellular networks
INTRODUCTION TO CLOUD COMPUTING

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Approach and Philosophy of On baking technology
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Cloud computing and distributed systems.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation theory and applications.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I
Spectral efficient network and resource selection model in 5G networks
Approach and Philosophy of On baking technology
MYSQL Presentation for SQL database connectivity
Cloud computing and distributed systems.
Mobile App Security Testing_ A Comprehensive Guide.pdf
A Presentation on Artificial Intelligence
KodekX | Application Modernization Development
NewMind AI Monthly Chronicles - July 2025
Building Integrated photovoltaic BIPV_UPV.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation theory and applications.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Electronic commerce courselecture one. Pdf

JDBC: java DataBase connectivity

  • 1. by Tanmoy Barman cont:- barmantanmoy.47@gmail.com
  • 2. Discussions  What?  Architecture of JDBC.  Types of JDBC driver available.  Steps to connect to DB.  Types of Statement.  JDBC Data Source.
  • 3. What is JDBC ?  JDBC acronym of java Database connectivity; though Sun Microsystems claims that it is not the full form.  JDBC is a standard java API for independent database connection between a java program and wide range of relational database.  It is present in the “java.sql” package
  • 5. Types of JDBC driver  Type 1; jdbc-odbc bridge driver  Type 2; native API partly java driver.  Type 3; net protocols all java driver.  Type 4; native protocols all java driver.
  • 6. Steps to connect?  Define the connection URL.  Established the connection.  Create the Statement object.  Execute a query.  Process the results.  Close the connection.
  • 7. Steps to connect?  Define the connection url : Class.forName();  For jdbc-odbc bridge driver:- Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);  For oracle driver:- Class.forName(“oracle.jdbc.driver.OracleDriver”);  For My sql driver:- Class.forName(“com.mysql.jdbc.Driver”);
  • 8. Steps to connect?  Established the connection: Connection con =DriverManager.getConnection(“url”,”user_name”,”pass”);
  • 9. Steps to connect?  Create the Statement object: Statement stmt=con.createStatement();
  • 10. Steps to connect?  Execute the query:  For the SELECT query:-  String sql=“SELECT * FROM EMP”;  stmt.executeQuery(sql);  For the INSERT/UPDATE query:-  String sql=“INSERT INTO EMP VALUES(47,’TEDDY’)”;  stmt.executeUpdate(sql);
  • 11. Steps to connect?  Process the result:- ResultSet rs=stmt.execute Query(sql); while(rs.next()){ System.out.println(rs.getInt(id)); System.out.print(rs.getString(name)); }
  • 12. Steps to connect?  Close the connection release all the resources that the connection is holding. stmt.close(); con.close();
  • 13. Steps to connect?  Summarizing the steps for connecting java DB and inserting values in DB, deployed on Net Beans IDE :- Class.forName("org.apache.derby.jdbc.ClientDriver"); Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/orbacus","teddy","teddy"); Statement stmt=con.createStatement(); String sql=“INSERT INTO TEDDY(47,’jani’)”; stmt.executeUpdate(sql); stmt.close(); con.close();
  • 14. Types of Statement available  There are three types of Statement available in Statement class:-  Statement  PreparedStatement  CallableStatement
  • 15. Types of Statement available  Statement This represent a simple sql/mysql statement. Statement stmt=con.createStatement();
  • 16. Types of Statement available  PreparedStatement this represent precompiled sql/my sql statement which allows improved performance. It allows to execute the query multiple times and we can set the values according to our need. PreparedStatement psmt=con.prepareStatement();
  • 17. Types of Statement available  CallableStatement This allows the access of stored procedures; that are stored on the database. CallableStatement csmt=con.prepareCall();
  • 18. JDBC Data Source  The JDBC data source interface is an alternative to DriverManager class and conventional JBDC url. All the database information is present in the Naming service and retrieved using the JNDI API. The Data Source object contains the connection information which will make the actual connection and execute the JDBC commands.
  • 19. JDBC Data Source:  Each Data Source is assigned a logical name by conventional beginning with jdbc/ .  Advantages:- ○ Makes the code portable and reuse. ○ The application does not have to remember the hardcore driver information. ○ Connection pooling and distributed transaction advantages is facilitate.
  • 20. JDBC Data Source:  Syntax:- Context ctx=new InitialContext(); DataSource ds=(DataSource)ctx.lookup(“jdbc/teddyDB”); Connection con=ds.getConnection(“user_name”,”pass”);