SlideShare a Scribd company logo
1 of 21
JDBC
By,
K.B.Snega, M.sc(cs).,
Discussions
 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:1
527/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:
o Statement
o PreparedStatement
o 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:
o Makes the code portable and reuse.
o 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

Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
backdoor
 

What's hot (20)

Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript Programming
 

Similar to Jdbc

jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
DrMeenakshiS
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
jdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxjdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptx
ssuser8878c1
 

Similar to Jdbc (20)

Jdbc
JdbcJdbc
Jdbc
 
Jdbc
JdbcJdbc
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
 
JDBC
JDBCJDBC
JDBC
 
Jdbc
JdbcJdbc
Jdbc
 
Select query in JDBC
Select query in JDBCSelect query in JDBC
Select query in JDBC
 
11. jdbc
11. jdbc11. jdbc
11. jdbc
 
Jdbc new
Jdbc newJdbc new
Jdbc new
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptx
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
Jdbc introduction
Jdbc introductionJdbc introduction
Jdbc introduction
 
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 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)
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
Lecture17
Lecture17Lecture17
Lecture17
 
jdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxjdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptx
 

More from Ishucs (20)

Renuga
RenugaRenuga
Renuga
 
Snega
SnegaSnega
Snega
 
Thresholding
ThresholdingThresholding
Thresholding
 
Ishwariya
IshwariyaIshwariya
Ishwariya
 
Image compression
Image compressionImage compression
Image compression
 
Deepika
DeepikaDeepika
Deepika
 
Snega
SnegaSnega
Snega
 
Renuga
RenugaRenuga
Renuga
 
Soundharya
SoundharyaSoundharya
Soundharya
 
Lavanya
LavanyaLavanya
Lavanya
 
M.srinandhini
M.srinandhiniM.srinandhini
M.srinandhini
 
Deepika t
Deepika tDeepika t
Deepika t
 
Sragavi (1)
Sragavi (1)Sragavi (1)
Sragavi (1)
 
Ishwariya
IshwariyaIshwariya
Ishwariya
 
Software enginnering
Software enginneringSoftware enginnering
Software enginnering
 
Partial redundancy elimination
Partial redundancy eliminationPartial redundancy elimination
Partial redundancy elimination
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
Web programming
Web programmingWeb programming
Web programming
 
Big data
Big dataBig data
Big data
 
Affine array index
Affine array indexAffine array index
Affine array index
 

Recently uploaded

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 

Recently uploaded (20)

Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 

Jdbc

  • 2. Discussions  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:1 527/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: o Statement o PreparedStatement o 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: o Makes the code portable and reuse. o 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”);