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
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
Guo Albert
 

What's hot (20)

JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Computer Science:Java jdbc
Computer Science:Java jdbcComputer Science:Java jdbc
Computer Science:Java jdbc
 
Spring boot
Spring bootSpring boot
Spring boot
 
Introduction to java 8 stream api
Introduction to java 8 stream apiIntroduction to java 8 stream api
Introduction to java 8 stream api
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
JPA For Beginner's
JPA For Beginner'sJPA For Beginner's
JPA For Beginner's
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Java collections
Java collectionsJava collections
Java collections
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & Streams
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 

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

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 

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