SlideShare a Scribd company logo
SERVLETS & JDBC
BY
K.SIVAPRIYA
MS.c(Info.tech)
Nadar Saraswathi College Of Arts &Science
SERVLETS
Servlets provide a component-based, platform-
independent method for building Web-based
applications, without the performance limitations of CGI
programs. Servlets have access to the entire family of
Java APIs, including the JDBC API to access enterprise
databases
Why to Learn Servlet?
Using Servlets, you can collect input from users through
web page forms, present records from a database or
another source, and create web pages dynamically.
Java Servlets often serve the same purpose as programs
implemented using the Common Gateway Interface
(CGI). But Servlets offer several advantages in
comparison with the CGI.
CONT…
Performance is significantly better.
Servlets execute within the address space of a Web server.
It is not necessary to create a separate process to handle
each client request.
Servlets are platform-independent because they are written
in Java.
CONT…
Java security manager on the server enforces a set of
restrictions to protect the resources on a server machine.
So servlets are trusted.
The full functionality of the Java class libraries is available
to a servlet. It can communicate with applets, databases,
or other software via the sockets and RMI mechanisms
that you have seen already.
LIFE CYCLE OF SERVELTS
A servlet life cycle can be defined as the entire process
from its creation till the destruction. The following are
the paths followed by a servlet.
The servlet is initialized by calling the init() method.
The servlet calls service() method to process a client's
request.
The servlet is terminated by calling the destroy() method.
CONT…
Finally, servlet is garbage collected by the garbage
collector of the JVM.
Now let us discuss the life cycle methods in detail.
init() Method
The init method is called only once. It is called only when
the servlet is created, and not called for any user requests
afterwards. So, it is used for one-time initializations, just
as with the init method of applets.
The servlet is normally created when a user first invokes a
URL corresponding to the servlet, but you can also
specify that the servlet be loaded when the server is first
started.
CONT…
When a user invokes a servlet, a single instance of each
servlet gets created, with each user request resulting in a
new thread that is handed off to doGet or doPost as
appropriate. The init() method simply creates or loads
some data that will be used throughout the life of the
servlet.
The init method definition looks like this
public void init() throws ServletException { // Initialization
code... }
service() Method
The service() method is the main method to perform the
actual task. The servlet container calls the service()
method to handle requests coming from the client and to
write the formatted response back to the client.
Each time the server receives a request for a servlet, the
server spawns a new thread and calls service. The
service() method checks the HTTP request type (GET,
POST, PUT, DELETE, etc.) and calls doGet, doPost,
doPut, doDelete, etc. methods as appropriate.
doGet() Method & doPost() Method
• A GET request results from a normal request for a URL
or from an HTML form that has no METHOD specified
and it should be handled by doGet() method.
• A POST request results from an HTML form that
specifically lists POST as the METHOD and it should be
handled by doPost() method.
destroy() Method
The destroy() method is called only once at the end of the
life cycle of a servlet. This method gives your servlet a
chance to close database connections, halt background
threads, write cookie lists or hit counts to disk, and
perform other such cleanup activities.
After the destroy() method is called, the servlet object is
marked for garbage collection.
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. There are four types of JDBC drivers:
• JDBC-ODBC Bridge Driver,
• Native Driver,
• Network Protocol Driver, and
• Thin Driver
CONT…
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. It is like Open Database Connectivity (ODBC)
provided by Microsoft.
The current version of JDBC is 4.3. It is the stable
release since 21st September, 2017. It is based on the
X/Open SQL Call Level Interface. The java.sql package
contains classes and interfaces for JDBC API.
A list of popular interfaces of JDBC
API
• Driver interface
• Connection interface
• Statement interface
• Prepared Statement interface
• CallableStatement interface
• ResultSet interface
• ResultSetMetaData interface
• DatabaseMetaData interface
• RowSet interface

More Related Content

PPTX
Android styles and themes
PPTX
Spring JDBCTemplate
PPT
Node js Modules and Event Emitters
PDF
Headaches of Blocking, Locking, and Deadlocking
PPTX
servlet in java
PPTX
SQL Injection Introduction and Prevention
PPTX
Cyber Security(Password Cracking Presentation).pptx
PPTX
Spring boot Introduction
Android styles and themes
Spring JDBCTemplate
Node js Modules and Event Emitters
Headaches of Blocking, Locking, and Deadlocking
servlet in java
SQL Injection Introduction and Prevention
Cyber Security(Password Cracking Presentation).pptx
Spring boot Introduction

What's hot (20)

PDF
Introduction to fragments in android
PPT
Chapter 01
PPSX
Sessions and cookies
PPTX
Как писать красивый код или основы SOLID
PDF
Android ui dialog
PDF
[Android] Widget Event Handling
PDF
Spring Framework - AOP
PPTX
What is component in reactjs
PPT
Webservices
PDF
Hibernate Presentation
PPTX
Authentication and Authorization in Asp.Net
PPT
Javascript
PPTX
Java Server Pages
PDF
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
PDF
Password (in)security
PPS
Java rmi
PPTX
PPT
Jsp ppt
PPT
URL Class in JAVA
Introduction to fragments in android
Chapter 01
Sessions and cookies
Как писать красивый код или основы SOLID
Android ui dialog
[Android] Widget Event Handling
Spring Framework - AOP
What is component in reactjs
Webservices
Hibernate Presentation
Authentication and Authorization in Asp.Net
Javascript
Java Server Pages
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
Password (in)security
Java rmi
Jsp ppt
URL Class in JAVA
Ad

Similar to Servlets & jdbc (20)

DOCX
Major project report
PPTX
DOCX
Online grocery store
PPTX
Java Servlet
PPT
Presentation on java servlets
PPTX
SERVLET in web technolgy engineering.pptx
PPT
Java Database Connectivity
PPTX
Servlet.pptx
PPTX
Servlet.pptx
PPTX
Advance Java Programming (CM5I) 6.Servlet
PPTX
Core jdbc basics
PPTX
J servlets
PPTX
E-MARKETING E-ZONE PPT Using ADVANCED JAVA
PPTX
Wt unit 3
PDF
Enterprise Java, Servlet, JDBC and JSP.pdf
PPT
JDBC.ppt
PPTX
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
PPT
Servlet 01
DOCX
J2EE-assignment
PPTX
AJppt.pptx
Major project report
Online grocery store
Java Servlet
Presentation on java servlets
SERVLET in web technolgy engineering.pptx
Java Database Connectivity
Servlet.pptx
Servlet.pptx
Advance Java Programming (CM5I) 6.Servlet
Core jdbc basics
J servlets
E-MARKETING E-ZONE PPT Using ADVANCED JAVA
Wt unit 3
Enterprise Java, Servlet, JDBC and JSP.pdf
JDBC.ppt
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
Servlet 01
J2EE-assignment
AJppt.pptx
Ad

More from Siva Priya (12)

PPTX
source code metrics and other maintenance tools and techniques
PPTX
Class properties
PPTX
Planning the development process
PPTX
recovery management with concurrent controls
PPTX
Web technology
PPTX
Retail of big data analytics
PPTX
Deadlock and shadow paging
PPT
Mobile IP
PPTX
density based method and expectation maximization
PPTX
Classification by backpropacation
PPTX
Disk scheduling & Disk management
PPTX
Routing algorithm
source code metrics and other maintenance tools and techniques
Class properties
Planning the development process
recovery management with concurrent controls
Web technology
Retail of big data analytics
Deadlock and shadow paging
Mobile IP
density based method and expectation maximization
Classification by backpropacation
Disk scheduling & Disk management
Routing algorithm

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation theory and applications.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
Teaching material agriculture food technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Reach Out and Touch Someone: Haptics and Empathic Computing
Digital-Transformation-Roadmap-for-Companies.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
The AUB Centre for AI in Media Proposal.docx
Encapsulation theory and applications.pdf
Machine learning based COVID-19 study performance prediction
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Diabetes mellitus diagnosis method based random forest with bat algorithm
Teaching material agriculture food technology
NewMind AI Weekly Chronicles - August'25 Week I
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
20250228 LYD VKU AI Blended-Learning.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...

Servlets & jdbc

  • 1. SERVLETS & JDBC BY K.SIVAPRIYA MS.c(Info.tech) Nadar Saraswathi College Of Arts &Science
  • 2. SERVLETS Servlets provide a component-based, platform- independent method for building Web-based applications, without the performance limitations of CGI programs. Servlets have access to the entire family of Java APIs, including the JDBC API to access enterprise databases
  • 3. Why to Learn Servlet? Using Servlets, you can collect input from users through web page forms, present records from a database or another source, and create web pages dynamically. Java Servlets often serve the same purpose as programs implemented using the Common Gateway Interface (CGI). But Servlets offer several advantages in comparison with the CGI.
  • 4. CONT… Performance is significantly better. Servlets execute within the address space of a Web server. It is not necessary to create a separate process to handle each client request. Servlets are platform-independent because they are written in Java.
  • 5. CONT… Java security manager on the server enforces a set of restrictions to protect the resources on a server machine. So servlets are trusted. The full functionality of the Java class libraries is available to a servlet. It can communicate with applets, databases, or other software via the sockets and RMI mechanisms that you have seen already.
  • 6. LIFE CYCLE OF SERVELTS A servlet life cycle can be defined as the entire process from its creation till the destruction. The following are the paths followed by a servlet. The servlet is initialized by calling the init() method. The servlet calls service() method to process a client's request. The servlet is terminated by calling the destroy() method.
  • 7. CONT… Finally, servlet is garbage collected by the garbage collector of the JVM. Now let us discuss the life cycle methods in detail.
  • 8. init() Method The init method is called only once. It is called only when the servlet is created, and not called for any user requests afterwards. So, it is used for one-time initializations, just as with the init method of applets. The servlet is normally created when a user first invokes a URL corresponding to the servlet, but you can also specify that the servlet be loaded when the server is first started.
  • 9. CONT… When a user invokes a servlet, a single instance of each servlet gets created, with each user request resulting in a new thread that is handed off to doGet or doPost as appropriate. The init() method simply creates or loads some data that will be used throughout the life of the servlet. The init method definition looks like this public void init() throws ServletException { // Initialization code... }
  • 10. service() Method The service() method is the main method to perform the actual task. The servlet container calls the service() method to handle requests coming from the client and to write the formatted response back to the client. Each time the server receives a request for a servlet, the server spawns a new thread and calls service. The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc. methods as appropriate.
  • 11. doGet() Method & doPost() Method • A GET request results from a normal request for a URL or from an HTML form that has no METHOD specified and it should be handled by doGet() method. • A POST request results from an HTML form that specifically lists POST as the METHOD and it should be handled by doPost() method.
  • 12. destroy() Method The destroy() method is called only once at the end of the life cycle of a servlet. This method gives your servlet a chance to close database connections, halt background threads, write cookie lists or hit counts to disk, and perform other such cleanup activities. After the destroy() method is called, the servlet object is marked for garbage collection.
  • 13. 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. There are four types of JDBC drivers: • JDBC-ODBC Bridge Driver, • Native Driver, • Network Protocol Driver, and • Thin Driver
  • 14. CONT… 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. It is like Open Database Connectivity (ODBC) provided by Microsoft. The current version of JDBC is 4.3. It is the stable release since 21st September, 2017. It is based on the X/Open SQL Call Level Interface. The java.sql package contains classes and interfaces for JDBC API.
  • 15. A list of popular interfaces of JDBC API • Driver interface • Connection interface • Statement interface • Prepared Statement interface • CallableStatement interface • ResultSet interface • ResultSetMetaData interface • DatabaseMetaData interface • RowSet interface