SlideShare a Scribd company logo
JAVA JDBC
Seena. K
Assistant Professor
Department of Vocational Studies
St. Mary’s College, Thrissur
Java JDBC,Seena.k.,St.Mary’s College
Java JDBC
JDBC stands for Java Database Connectivity. JDBC is a Java API to
connect and execute the query with the database
. It is a part of JavaSE (Java Standard Edition). JDBC API uses JDBC
drivers to connect with the database.
“It is a Java-based data access technology used for Java database
connectivity.
 It provides methods to query and update data in a database, and is
oriented towards relational Databases
Java JDBC,Seena.k.,St.Mary’s College
JDBC Drivers
There are four types of JDBC drivers
1. JDBC-ODBC Bridge Driver,
2. Native Driver,
3. Network Protocol Driver, and Thin Driver
Java JDBC,Seena.k.,St.Mary’s College
 We can use JDBC API to access tabular data stored in any relational
database. By the help of JDBC API, we can save, update, delete and
fetch data from the database.
Java JDBC,seena.K,St.Mary’s College
 We can use JDBC API to handle database using Java program and can perform
the following activities:
1. Connect to the database
2. Execute queries and update statements to the database
3. Retrieve the result received from the database.
 It is based on the X/Open SQL Call Level Interface.
 The java.sql package contains classes and interfaces for JDBC API
Java JDBC,Seena.k,St.Mar’ys College
Classes and Interfaces Of JDBC API
The java.sql package contains classes and interfaces for JDBC API. A
list of popular interfaces of JDBC API are given below:
Classes Interfaces
1. DriverManager class 1. Driver Interface
2. Blob class 2. Connection Interface
3. Clob class 3. Statement Interface
4. Types class 4. PreparedStatement Interface &
ResultSet Interface
Java JDBC,Seena.k,St.Mar’ys College
What is API
 API (Application programming interface) is a document that
contains a description of all the features of a product or software.
 It represents classes and interfaces that software programs can
follow to communicate with each other. An API can be created for
applications, libraries, operating systems,
Java JDBC,Seena.K,St.Mary’s College
Java Database Connectivity with 5 Steps
 There are 5 steps to connect any java application with the database
using JDBC. These steps are as follows:
1. Register the Driver class
2. Create connection
3. Create statement
4. Execute queries
5. Close connection
Java JDBC,Seena.K,St.Mary’s College
 The forName() method of class is used to register the driver class.
This method is used to dynamically load the driver class.
 The DriverManager class acts as an interface between user and
drivers. It keeps track of the drivers that are available and handles
establishing a connection between a database and the appropriate
driver.
Register the driver class
Java JDBC,Seena.K,St.Mary’s College
 A Connection is the session between java application and database. The
Connection interface is a factory of Statement, PreparedStatement, and
DatabaseMetaData i.e. object of Connection can be used to get the object
of Statement and DatabaseMetaData.
 public Statement createStatement(): creates a statement object that can
be used to execute SQL queries.
Connection interface
Java JDBC,Seena.K,St.Mary’s College
 The Statement interface provides methods to execute queries
with the database. The statement interface is a factory of
ResultSet i.e. it provides factory method to get the object of
ResultSet.
 public ResultSet executeQuery(String sql): is used to execute
SELECT query. It returns the object of ResultSet.
Statement interface
Java JDBC,Seena.K,St.Mary’s College
 The object of ResultSet maintains a cursor pointing to a row of a table.
Initially, cursor points to before the first row.
ResultSet Interface
public boolean next(): is used to move the cursor to the
one row next from the current
position.
3) public boolean first(): is used to move the cursor to the
first row in result set object.
4) public boolean last(): is used to move the cursor to the
last row in result set object.
Java JDBC,Seena.k,St.Mar’ys College
To connect Java application with the MySQL database, we need to follow
5 following steps.
 Driver class: The driver class for the mysql database
is com.mysql.jdbc.Driver.
 Connection URL: The connection URL for the mysql database
is jdbc:mysql://localhost:3306/sonoo where jdbc is the API, mysql is
the database, localhost is the server name on which mysql is running,
we may also use IP address, 3306 is the port number.
Java Database Connectivity with MySQL
Java JDBC,Seena.k,St.Mar’ys College
Username: The default username for the mysql database is root.
Password: It is the password given by the user at the time of installing
the mysql database. In this example, we are going to use root as the
password.
Java Database Connectivity with MySQL
Java JDBC,Seena.k,St.Mar’ys College
import java.sql.*;
class MysqlCon{
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sonoo","root","root");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}catch(Exception e){ System.out.println(e);} }}
Example to Connect Java Application with
mysql database
Java JDBC,Seena.k,St.Mar’ys College
REFERENCE
www.javatpoint.com
Ad

More Related Content

What's hot (20)

Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
Indu Sharma Bhardwaj
 
JDBC
JDBCJDBC
JDBC
People Strategists
 
Java rmi
Java rmiJava rmi
Java rmi
kamal kotecha
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
Pooja Talreja
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Lovely Professional University
 
Access Modifier.pptx
Access Modifier.pptxAccess Modifier.pptx
Access Modifier.pptx
Margaret Mary
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
CPD INDIA
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Android adapters
Android adaptersAndroid adapters
Android adapters
baabtra.com - No. 1 supplier of quality freshers
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
Pooja Jaiswal
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserialization
Young Alista
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
Spotle.ai
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
Jalpesh Vasa
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 

Similar to Computer Science:Java jdbc (20)

Jdbc slide for beginers
Jdbc slide for beginersJdbc slide for beginers
Jdbc slide for beginers
Ambarish Rai
 
Jdbc
JdbcJdbc
Jdbc
Ravi_Kant_Sahu
 
Jdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbc
Jdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbcJdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbc
Jdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbc
rohanbawadkar
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connection
Paneliya Prince
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connection
Paneliya Prince
 
Core jdbc basics
Core jdbc basicsCore jdbc basics
Core jdbc basics
Sourabrata Mukherjee
 
JDBC-Introduction
JDBC-IntroductionJDBC-Introduction
JDBC-Introduction
Mythili Shankar
 
Introduction to Java Database Connectivity (JDBC)
Introduction to Java Database Connectivity (JDBC)Introduction to Java Database Connectivity (JDBC)
Introduction to Java Database Connectivity (JDBC)
Naresh IT
 
Fundamentals of JDBC
Fundamentals of JDBCFundamentals of JDBC
Fundamentals of JDBC
Jainul Musani
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
suraj pandey
 
Introduction to advanced java
Introduction to advanced javaIntroduction to advanced java
Introduction to advanced java
kritikumar16
 
5 things about introduction to advanced java you have to experience it yourself.
5 things about introduction to advanced java you have to experience it yourself.5 things about introduction to advanced java you have to experience it yourself.
5 things about introduction to advanced java you have to experience it yourself.
kritikumar16
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
Arumugam90
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
Arumugam90
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
Java Database Connectivity by shreyash simu dbce.pptx
Java Database Connectivity by shreyash simu dbce.pptxJava Database Connectivity by shreyash simu dbce.pptx
Java Database Connectivity by shreyash simu dbce.pptx
ash909077
 
Java Data Base Connectivity concepts.pptx
Java Data Base Connectivity concepts.pptxJava Data Base Connectivity concepts.pptx
Java Data Base Connectivity concepts.pptx
mukeshprasanth909
 
JDBC PPT(4).pptx java Database Connectivity
JDBC PPT(4).pptx java Database ConnectivityJDBC PPT(4).pptx java Database Connectivity
JDBC PPT(4).pptx java Database Connectivity
dhanushoneplus00
 
435819601-Advanced-Java_Study About Java.pptx
435819601-Advanced-Java_Study About Java.pptx435819601-Advanced-Java_Study About Java.pptx
435819601-Advanced-Java_Study About Java.pptx
JPrince9
 
Jdbc slide for beginers
Jdbc slide for beginersJdbc slide for beginers
Jdbc slide for beginers
Ambarish Rai
 
Jdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbc
Jdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbcJdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbc
Jdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbc
rohanbawadkar
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connection
Paneliya Prince
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connection
Paneliya Prince
 
Introduction to Java Database Connectivity (JDBC)
Introduction to Java Database Connectivity (JDBC)Introduction to Java Database Connectivity (JDBC)
Introduction to Java Database Connectivity (JDBC)
Naresh IT
 
Fundamentals of JDBC
Fundamentals of JDBCFundamentals of JDBC
Fundamentals of JDBC
Jainul Musani
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
suraj pandey
 
Introduction to advanced java
Introduction to advanced javaIntroduction to advanced java
Introduction to advanced java
kritikumar16
 
5 things about introduction to advanced java you have to experience it yourself.
5 things about introduction to advanced java you have to experience it yourself.5 things about introduction to advanced java you have to experience it yourself.
5 things about introduction to advanced java you have to experience it yourself.
kritikumar16
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
Arumugam90
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
Arumugam90
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
Java Database Connectivity by shreyash simu dbce.pptx
Java Database Connectivity by shreyash simu dbce.pptxJava Database Connectivity by shreyash simu dbce.pptx
Java Database Connectivity by shreyash simu dbce.pptx
ash909077
 
Java Data Base Connectivity concepts.pptx
Java Data Base Connectivity concepts.pptxJava Data Base Connectivity concepts.pptx
Java Data Base Connectivity concepts.pptx
mukeshprasanth909
 
JDBC PPT(4).pptx java Database Connectivity
JDBC PPT(4).pptx java Database ConnectivityJDBC PPT(4).pptx java Database Connectivity
JDBC PPT(4).pptx java Database Connectivity
dhanushoneplus00
 
435819601-Advanced-Java_Study About Java.pptx
435819601-Advanced-Java_Study About Java.pptx435819601-Advanced-Java_Study About Java.pptx
435819601-Advanced-Java_Study About Java.pptx
JPrince9
 
Ad

More from St Mary's College,Thrissur,Kerala (20)

Creative writing and literature
Creative writing and literature Creative writing and literature
Creative writing and literature
St Mary's College,Thrissur,Kerala
 
Magnetic Tape
Magnetic TapeMagnetic Tape
Magnetic Tape
St Mary's College,Thrissur,Kerala
 
Online Data Storage
Online Data StorageOnline Data Storage
Online Data Storage
St Mary's College,Thrissur,Kerala
 
Mathematics:Cryptography
Mathematics:CryptographyMathematics:Cryptography
Mathematics:Cryptography
St Mary's College,Thrissur,Kerala
 
Mathematics:Arithmetical Functions
Mathematics:Arithmetical FunctionsMathematics:Arithmetical Functions
Mathematics:Arithmetical Functions
St Mary's College,Thrissur,Kerala
 
Physical education :Yoga For Stress Relief
Physical education :Yoga For Stress ReliefPhysical education :Yoga For Stress Relief
Physical education :Yoga For Stress Relief
St Mary's College,Thrissur,Kerala
 
Psychology:PAIN: Types, Theories and Assessment of pain
Psychology:PAIN: Types, Theories and  Assessment of pain Psychology:PAIN: Types, Theories and  Assessment of pain
Psychology:PAIN: Types, Theories and Assessment of pain
St Mary's College,Thrissur,Kerala
 
Economics:Functions
Economics:FunctionsEconomics:Functions
Economics:Functions
St Mary's College,Thrissur,Kerala
 
Mathematics:H-Complexity
Mathematics:H-ComplexityMathematics:H-Complexity
Mathematics:H-Complexity
St Mary's College,Thrissur,Kerala
 
Statistics:Probability Theory
Statistics:Probability TheoryStatistics:Probability Theory
Statistics:Probability Theory
St Mary's College,Thrissur,Kerala
 
Statistics:Fundamentals Of Statistics
Statistics:Fundamentals Of StatisticsStatistics:Fundamentals Of Statistics
Statistics:Fundamentals Of Statistics
St Mary's College,Thrissur,Kerala
 
Economics:Public Revenue
Economics:Public RevenueEconomics:Public Revenue
Economics:Public Revenue
St Mary's College,Thrissur,Kerala
 
Economics:Public Debt
Economics:Public  DebtEconomics:Public  Debt
Economics:Public Debt
St Mary's College,Thrissur,Kerala
 
Economics:Poverty-perspectives And Dimensions
Economics:Poverty-perspectives And DimensionsEconomics:Poverty-perspectives And Dimensions
Economics:Poverty-perspectives And Dimensions
St Mary's College,Thrissur,Kerala
 
Economics:Economic Integration
Economics:Economic IntegrationEconomics:Economic Integration
Economics:Economic Integration
St Mary's College,Thrissur,Kerala
 
Economics:Enviornmental Pollution
Economics:Enviornmental Pollution Economics:Enviornmental Pollution
Economics:Enviornmental Pollution
St Mary's College,Thrissur,Kerala
 
Computer Science:JavaScript
Computer Science:JavaScript Computer Science:JavaScript
Computer Science:JavaScript
St Mary's College,Thrissur,Kerala
 
Computer Science:Sql Set Operation
Computer Science:Sql Set OperationComputer Science:Sql Set Operation
Computer Science:Sql Set Operation
St Mary's College,Thrissur,Kerala
 
Microbiology:General Principles of Food Preservation
Microbiology:General Principles of Food PreservationMicrobiology:General Principles of Food Preservation
Microbiology:General Principles of Food Preservation
St Mary's College,Thrissur,Kerala
 
Microbiology:Induction Course-Introduction to Medical Microbiology
Microbiology:Induction Course-Introduction to Medical MicrobiologyMicrobiology:Induction Course-Introduction to Medical Microbiology
Microbiology:Induction Course-Introduction to Medical Microbiology
St Mary's College,Thrissur,Kerala
 
Microbiology:Induction Course-Introduction to Medical Microbiology
Microbiology:Induction Course-Introduction to Medical MicrobiologyMicrobiology:Induction Course-Introduction to Medical Microbiology
Microbiology:Induction Course-Introduction to Medical Microbiology
St Mary's College,Thrissur,Kerala
 
Ad

Recently uploaded (20)

Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 

Computer Science:Java jdbc

  • 1. JAVA JDBC Seena. K Assistant Professor Department of Vocational Studies St. Mary’s College, Thrissur
  • 2. Java JDBC,Seena.k.,St.Mary’s College Java JDBC JDBC stands for Java Database Connectivity. JDBC is a Java API to connect and execute the query with the database . It is a part of JavaSE (Java Standard Edition). JDBC API uses JDBC drivers to connect with the database. “It is a Java-based data access technology used for Java database connectivity.  It provides methods to query and update data in a database, and is oriented towards relational Databases
  • 3. Java JDBC,Seena.k.,St.Mary’s College JDBC Drivers There are four types of JDBC drivers 1. JDBC-ODBC Bridge Driver, 2. Native Driver, 3. Network Protocol Driver, and Thin Driver
  • 4. Java JDBC,Seena.k.,St.Mary’s College  We can use JDBC API to access tabular data stored in any relational database. By the help of JDBC API, we can save, update, delete and fetch data from the database.
  • 5. Java JDBC,seena.K,St.Mary’s College  We can use JDBC API to handle database using Java program and can perform the following activities: 1. Connect to the database 2. Execute queries and update statements to the database 3. Retrieve the result received from the database.  It is based on the X/Open SQL Call Level Interface.  The java.sql package contains classes and interfaces for JDBC API
  • 6. Java JDBC,Seena.k,St.Mar’ys College Classes and Interfaces Of JDBC API The java.sql package contains classes and interfaces for JDBC API. A list of popular interfaces of JDBC API are given below: Classes Interfaces 1. DriverManager class 1. Driver Interface 2. Blob class 2. Connection Interface 3. Clob class 3. Statement Interface 4. Types class 4. PreparedStatement Interface & ResultSet Interface
  • 7. Java JDBC,Seena.k,St.Mar’ys College What is API  API (Application programming interface) is a document that contains a description of all the features of a product or software.  It represents classes and interfaces that software programs can follow to communicate with each other. An API can be created for applications, libraries, operating systems,
  • 8. Java JDBC,Seena.K,St.Mary’s College Java Database Connectivity with 5 Steps  There are 5 steps to connect any java application with the database using JDBC. These steps are as follows: 1. Register the Driver class 2. Create connection 3. Create statement 4. Execute queries 5. Close connection
  • 9. Java JDBC,Seena.K,St.Mary’s College  The forName() method of class is used to register the driver class. This method is used to dynamically load the driver class.  The DriverManager class acts as an interface between user and drivers. It keeps track of the drivers that are available and handles establishing a connection between a database and the appropriate driver. Register the driver class
  • 10. Java JDBC,Seena.K,St.Mary’s College  A Connection is the session between java application and database. The Connection interface is a factory of Statement, PreparedStatement, and DatabaseMetaData i.e. object of Connection can be used to get the object of Statement and DatabaseMetaData.  public Statement createStatement(): creates a statement object that can be used to execute SQL queries. Connection interface
  • 11. Java JDBC,Seena.K,St.Mary’s College  The Statement interface provides methods to execute queries with the database. The statement interface is a factory of ResultSet i.e. it provides factory method to get the object of ResultSet.  public ResultSet executeQuery(String sql): is used to execute SELECT query. It returns the object of ResultSet. Statement interface
  • 12. Java JDBC,Seena.K,St.Mary’s College  The object of ResultSet maintains a cursor pointing to a row of a table. Initially, cursor points to before the first row. ResultSet Interface public boolean next(): is used to move the cursor to the one row next from the current position. 3) public boolean first(): is used to move the cursor to the first row in result set object. 4) public boolean last(): is used to move the cursor to the last row in result set object.
  • 13. Java JDBC,Seena.k,St.Mar’ys College To connect Java application with the MySQL database, we need to follow 5 following steps.  Driver class: The driver class for the mysql database is com.mysql.jdbc.Driver.  Connection URL: The connection URL for the mysql database is jdbc:mysql://localhost:3306/sonoo where jdbc is the API, mysql is the database, localhost is the server name on which mysql is running, we may also use IP address, 3306 is the port number. Java Database Connectivity with MySQL
  • 14. Java JDBC,Seena.k,St.Mar’ys College Username: The default username for the mysql database is root. Password: It is the password given by the user at the time of installing the mysql database. In this example, we are going to use root as the password. Java Database Connectivity with MySQL
  • 15. Java JDBC,Seena.k,St.Mar’ys College import java.sql.*; class MysqlCon{ public static void main(String args[]){ try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection( "jdbc:mysql://localhost:3306/sonoo","root","root"); Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery("select * from emp"); while(rs.next()) System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)); con.close(); }catch(Exception e){ System.out.println(e);} }} Example to Connect Java Application with mysql database