SlideShare a Scribd company logo
1 of 21
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

What's hot

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 

What's hot (20)

Applets in java
Applets in javaApplets in java
Applets in java
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Types of Drivers in JDBC
Types of Drivers in JDBCTypes of Drivers in JDBC
Types of Drivers in JDBC
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Java threads
Java threadsJava threads
Java threads
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 
Applets
AppletsApplets
Applets
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Java swing
Java swingJava swing
Java swing
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Java package
Java packageJava package
Java package
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
OOP java
OOP javaOOP java
OOP java
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 

Viewers also liked

Java Servlets
Java ServletsJava Servlets
Java Servlets
Nitin Pai
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
backdoor
 
Java Collections
Java CollectionsJava Collections
Java Collections
parag
 
Interface callable statement
Interface callable statementInterface callable statement
Interface callable statement
myrajendra
 
Java.sql package
Java.sql packageJava.sql package
Java.sql package
myrajendra
 

Viewers also liked (20)

JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
 
Jdbc
JdbcJdbc
Jdbc
 
Database Access With JDBC
Database Access With JDBCDatabase Access With JDBC
Database Access With JDBC
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Jdbc
JdbcJdbc
Jdbc
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
Interface callable statement
Interface callable statementInterface callable statement
Interface callable statement
 
Java.sql package
Java.sql packageJava.sql package
Java.sql package
 
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
JdbcJdbc
Jdbc
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBC
 
java Jdbc
java Jdbc java Jdbc
java Jdbc
 
Basic JSTL
Basic JSTLBasic JSTL
Basic JSTL
 

Similar to JDBC: java DataBase connectivity

jdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxjdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptx
ssuser8878c1
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
DrMeenakshiS
 

Similar to JDBC: java DataBase connectivity (20)

Jdbc
JdbcJdbc
Jdbc
 
Jdbc
Jdbc   Jdbc
Jdbc
 
JDBC
JDBCJDBC
JDBC
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptx
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc new
Jdbc newJdbc new
Jdbc new
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
Jdbc
JdbcJdbc
Jdbc
 
java arlow jdbc tutorial(java programming tutorials)
java arlow jdbc tutorial(java programming tutorials)java arlow jdbc tutorial(java programming tutorials)
java arlow jdbc tutorial(java programming tutorials)
 
JDBC
JDBCJDBC
JDBC
 
Jdbc introduction
Jdbc introductionJdbc introduction
Jdbc introduction
 
jdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxjdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptx
 
Prashanthi
PrashanthiPrashanthi
Prashanthi
 
Jdbc
JdbcJdbc
Jdbc
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
11. jdbc
11. jdbc11. jdbc
11. jdbc
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
 
10 J D B C
10  J D B C10  J D B C
10 J D B C
 

More from Tanmoy Barman (7)

Java rmi
Java rmiJava rmi
Java rmi
 
Jini
JiniJini
Jini
 
Java server pages
Java server pagesJava server pages
Java server pages
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Web apps architecture
Web apps architectureWeb apps architecture
Web apps architecture
 
introduction to channel borrowing scheme in cellular networks
introduction to channel borrowing scheme in cellular networksintroduction to channel borrowing scheme in cellular networks
introduction to channel borrowing scheme in cellular networks
 
INTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTINGINTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTING
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

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”);