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 (20)

Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Ajax and Jquery
Ajax and JqueryAjax and Jquery
Ajax and Jquery
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
JDBC
JDBCJDBC
JDBC
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Applets
AppletsApplets
Applets
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Java swing
Java swingJava swing
Java swing
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
Js ppt
Js pptJs ppt
Js ppt
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 

Viewers also liked

JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database ConnectivityRanjan Kumar
 
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 MySqlkamal kotecha
 
Java Servlets
Java ServletsJava Servlets
Java ServletsNitin Pai
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivitybackdoor
 
Java Collections
Java CollectionsJava Collections
Java Collectionsparag
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySqlDhyey Dattani
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySqlDhyey Dattani
 
Interface callable statement
Interface callable statementInterface callable statement
Interface callable statementmyrajendra
 
Java.sql package
Java.sql packageJava.sql package
Java.sql packagemyrajendra
 
JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)Craig Dickson
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBCDudy Ali
 

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 (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

Web apps architecture
Web apps architectureWeb apps architecture
Web apps architectureTanmoy Barman
 
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 networksTanmoy Barman
 
INTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTINGINTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTINGTanmoy Barman
 

More from Tanmoy Barman (6)

Java rmi
Java rmiJava rmi
Java rmi
 
Jini
JiniJini
Jini
 
Java server pages
Java server pagesJava server pages
Java server pages
 
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

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

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