SlideShare a Scribd company logo
1 of 15
Download to read offline
JDBC
1
Praveen Kumar Chandaliya (SCJP,SCWCD)
WHY JDBC
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D
2
package : java.sql.*
DESIGN OF JDBC
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D
3
JDBC DRIVER TYPE
 Type-1(JDBC-ODBCbridgedriver)
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D
4
TYPE 2(PARTLY JAVA AND PARTLY NATIVE CODE
DRIVER)
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D
5
TYPE-3(MIDDLEWARE)
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D
6
TYPE 4(PURE JAVA DRIVER)
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D
7
JDBC STEPS
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D 8
1. Finding the suitable driver (Type-4 Mysql)
String driver= “com.mysql.jdbc.Driver”;
2. Registration of suitable driver(Load driver)
try
{
Class.forName(driver);
}
catch(ClassNotFoundException ex)
{
}
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D
9
3. Physical Connection Establish between java Program
and My sql Data Base
Database url specific parameters as follows:
protocol : jdbc , sub protocal : mysql
Port numbers : 3306 ,Database names : jecrcdb
String url = “jdbc:mysql://ipaddress:3306/jecrcdb”;
String user=“username”; //root
String password=“password”; //root
try
{
Connection con = DriverManager.getConnection(url,user,password);
}
catch(SQLException ex)
{ }
4. Create Agent Who transfer sql Query from java program to
data base using connection
try
{ Statement stmt = con.createStatement();
}
catch(SQLException ex)
{ ex.printStackTrace(); }
5. Trigger Sql Query at Data Base side using statement
i) DDL (create,alter,drop)
stmt.execute(“create table student (sid int,sname varchar(30),email
varchar(30),branch varchar(20))”);
ii) DML (insert,delete,update)
stmt.executeUpdate(“insert into student
values(22,’praveen’,’pc@gmail.com’,’CSE’)”);
iii) DQL :(select)
ResultSet rs = stmt.executeQuery(“select *from student”)
P R A VE E N K U M A R C H A N D A L I YA ,
10
6. Close all resources in finally block
finally
{ try
{ if(stmt!=null) //Child Close First
{ stmt.close();
stmt =null;
}
}
catch(SQLException ex)
{}
try
{ if(con!=null) //Parent Close last
{ con.close();
con =null;
}
}
catch(SQLException ex)
{}
}
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D
11
STORE RESULT
 How to store result of the query
 ResultSet Interface
 Example
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D
12
Statementst = conn.createStatement();
. . .
ResultSetrs = st.executeQuery(“SELECT* FROM student”)
while(rs.next())
{
Look at a rowof the result set
}
Loop of Analyzing
RESULTSET
 Methods of ResultSetclass as follows:-
 boolean next()
 XXXX getXXXX(int columnNum);
 XXXX getXXXX(String columnLabel);
[XXXX -> int , double,String Date etc]
P R AVE E N KUM AR C HAN D ALIYA, S C J P, SCW CD
13
CLASS DIAGRAM OF CRUD OPEARTION
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D 14
Student
- sid : int
-sname : String
-email : String
-address: String
getXXX()
setXXX()
toString()
StudentDao
addStudent(Student st) : void
getAllStudent() : List
deleteStudent(int sid) : void
updateStudent(Student st):void
student student
StudentDataManager
Static {}
main() : void
DbUtility
static getConnection():Connection
P R A VE E N K U M A R C H A N D A L I YA ,
S C J P , S C WC D
15
Perform Insert,Delete,Update,Select operation

More Related Content

Viewers also liked

Final RKIC CaseStudy Presentation
Final  RKIC CaseStudy PresentationFinal  RKIC CaseStudy Presentation
Final RKIC CaseStudy PresentationSanford Terrance
 
La historia del perú
La historia del perúLa historia del perú
La historia del perúMelldr
 
Relación entre urbanismo y corrupción
Relación entre urbanismo y corrupciónRelación entre urbanismo y corrupción
Relación entre urbanismo y corrupciónIbiza Melián
 
Love Play UK, a sample of what you can find on our website.
Love Play UK, a sample of what you can find on our website.Love Play UK, a sample of what you can find on our website.
Love Play UK, a sample of what you can find on our website.Love Play UK at Nell's Emporium
 
Excel libro celda
Excel libro celdaExcel libro celda
Excel libro celdamales11
 

Viewers also liked (10)

Smart k
Smart kSmart k
Smart k
 
Notas de histologia 2014
Notas de histologia 2014Notas de histologia 2014
Notas de histologia 2014
 
Final RKIC CaseStudy Presentation
Final  RKIC CaseStudy PresentationFinal  RKIC CaseStudy Presentation
Final RKIC CaseStudy Presentation
 
La historia del perú
La historia del perúLa historia del perú
La historia del perú
 
Relación entre urbanismo y corrupción
Relación entre urbanismo y corrupciónRelación entre urbanismo y corrupción
Relación entre urbanismo y corrupción
 
ProCure Norman transcript
ProCure Norman transcriptProCure Norman transcript
ProCure Norman transcript
 
Love Play UK, a sample of what you can find on our website.
Love Play UK, a sample of what you can find on our website.Love Play UK, a sample of what you can find on our website.
Love Play UK, a sample of what you can find on our website.
 
La historia del peru
La historia del peruLa historia del peru
La historia del peru
 
Excel libro celda
Excel libro celdaExcel libro celda
Excel libro celda
 
Flood light revista
Flood light revista Flood light revista
Flood light revista
 

Similar to Jdbc

Similar to Jdbc (20)

Jdbc
JdbcJdbc
Jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQL
 
Jdbc tutorial
Jdbc tutorialJdbc tutorial
Jdbc tutorial
 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
 
Lecture17
Lecture17Lecture17
Lecture17
 
JDBC (2).ppt
JDBC (2).pptJDBC (2).ppt
JDBC (2).ppt
 
Java & banco de dados
Java & banco de dadosJava & banco de dados
Java & banco de dados
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
 
Core Java Programming Language (JSE) : Chapter XIII - JDBC
Core Java Programming Language (JSE) : Chapter XIII -  JDBCCore Java Programming Language (JSE) : Chapter XIII -  JDBC
Core Java Programming Language (JSE) : Chapter XIII - JDBC
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
 
Graph Database workshop
Graph Database workshopGraph Database workshop
Graph Database workshop
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBC
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Jdbc
JdbcJdbc
Jdbc
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Jdbc
JdbcJdbc
Jdbc
 
Lecture 1. java database connectivity
Lecture 1. java database connectivityLecture 1. java database connectivity
Lecture 1. java database connectivity
 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 

Jdbc

  • 2. WHY JDBC P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 2 package : java.sql.*
  • 3. DESIGN OF JDBC P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 3
  • 4. JDBC DRIVER TYPE  Type-1(JDBC-ODBCbridgedriver) P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 4
  • 5. TYPE 2(PARTLY JAVA AND PARTLY NATIVE CODE DRIVER) P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 5
  • 6. TYPE-3(MIDDLEWARE) P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 6
  • 7. TYPE 4(PURE JAVA DRIVER) P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 7
  • 8. JDBC STEPS P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 8 1. Finding the suitable driver (Type-4 Mysql) String driver= “com.mysql.jdbc.Driver”; 2. Registration of suitable driver(Load driver) try { Class.forName(driver); } catch(ClassNotFoundException ex) { }
  • 9. P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 9 3. Physical Connection Establish between java Program and My sql Data Base Database url specific parameters as follows: protocol : jdbc , sub protocal : mysql Port numbers : 3306 ,Database names : jecrcdb String url = “jdbc:mysql://ipaddress:3306/jecrcdb”; String user=“username”; //root String password=“password”; //root try { Connection con = DriverManager.getConnection(url,user,password); } catch(SQLException ex) { }
  • 10. 4. Create Agent Who transfer sql Query from java program to data base using connection try { Statement stmt = con.createStatement(); } catch(SQLException ex) { ex.printStackTrace(); } 5. Trigger Sql Query at Data Base side using statement i) DDL (create,alter,drop) stmt.execute(“create table student (sid int,sname varchar(30),email varchar(30),branch varchar(20))”); ii) DML (insert,delete,update) stmt.executeUpdate(“insert into student values(22,’praveen’,’pc@gmail.com’,’CSE’)”); iii) DQL :(select) ResultSet rs = stmt.executeQuery(“select *from student”) P R A VE E N K U M A R C H A N D A L I YA , 10
  • 11. 6. Close all resources in finally block finally { try { if(stmt!=null) //Child Close First { stmt.close(); stmt =null; } } catch(SQLException ex) {} try { if(con!=null) //Parent Close last { con.close(); con =null; } } catch(SQLException ex) {} } P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 11
  • 12. STORE RESULT  How to store result of the query  ResultSet Interface  Example P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 12 Statementst = conn.createStatement(); . . . ResultSetrs = st.executeQuery(“SELECT* FROM student”) while(rs.next()) { Look at a rowof the result set } Loop of Analyzing
  • 13. RESULTSET  Methods of ResultSetclass as follows:-  boolean next()  XXXX getXXXX(int columnNum);  XXXX getXXXX(String columnLabel); [XXXX -> int , double,String Date etc] P R AVE E N KUM AR C HAN D ALIYA, S C J P, SCW CD 13
  • 14. CLASS DIAGRAM OF CRUD OPEARTION P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 14 Student - sid : int -sname : String -email : String -address: String getXXX() setXXX() toString() StudentDao addStudent(Student st) : void getAllStudent() : List deleteStudent(int sid) : void updateStudent(Student st):void student student StudentDataManager Static {} main() : void DbUtility static getConnection():Connection
  • 15. P R A VE E N K U M A R C H A N D A L I YA , S C J P , S C WC D 15 Perform Insert,Delete,Update,Select operation