SlideShare a Scribd company logo
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

Smart k
Smart kSmart k
Smart k
志芳 陈
 
Notas de histologia 2014
Notas de histologia 2014Notas de histologia 2014
Notas de histologia 2014
Sebastian Castillo
 
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ón
Ibiza 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
 
La historia del peru
La historia del peruLa historia del peru
La historia del peru
Wilder Orellana
 
Excel libro celda
Excel libro celdaExcel libro celda
Excel libro celda
males11
 

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

Jdbc
JdbcJdbc
Jdbc
Indu Lata
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQL
Mark Wong
 
JDBC (2).ppt
JDBC (2).pptJDBC (2).ppt
JDBC (2).ppt
manvibaunthiyal1
 
Java & banco de dados
Java & banco de dadosJava & banco de dados
Java & banco de dados
Fábio José da Silva
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbcphanleson
 
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
WebStackAcademy
 
Jdbc
JdbcJdbc
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)Maher Abdo
 
Graph Database workshop
Graph Database workshopGraph Database workshop
Graph Database workshop
Jeremy Deane
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBC
Dudy Ali
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Atul Saurabh
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
Fahad Shaikh
 
Jdbc
JdbcJdbc
Jdbc
Ishucs
 
Lecture 1. java database connectivity
Lecture 1. java database connectivityLecture 1. java database connectivity
Lecture 1. java database connectivity
Waheedullah Suliman Khail
 

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

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 

Recently uploaded (20)

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 

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