SlideShare a Scribd company logo
Advanced java+JDBC+Servlet
JDBC (Java DataBase Connectivity)
There are four types of JDBC drivers:
1. JDBC-ODBC Bridge Driver
2. Native Driver
3. Network Protocol Driver
4. Thin Driver
1) JDBC-ODBC bridge driver
The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The
JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function calls.
This is now discouraged because of thin driver.
Advantages
1. easy to use.
2. can be easily connected to any database.
Disadvantages
1. Performance degraded because JDBC method call is converted into the ODBC function
calls.
2. The ODBC driver needs to be installed on the client machine.
2. Native-API driver
The Native API driver uses the client-side libraries of the database. The driver converts
JDBC method calls into native calls of the database API. It is not written entirely in java.
Advantages
1. performance upgraded than JDBC-ODBC bridge driver.
Disadvantages
1. The Native driver needs to be installed on the each client machine.
2. The Vendor client library needs to be installed on client machine.
3) Network Protocol driver
The Network Protocol driver uses middleware (application server) that converts JDBC calls
directly or indirectly into the vendor-specific database protocol. It is fully written in java.
Advantages
1. No client side library is required because of application server that can perform many
tasks like auditing, load balancing, logging etc..
Disadvantages
1. Network support is required on client machine.
2. Requires database-specific coding to be done in the middle tier.
3. Maintenance of Network Protocol driver becomes costly because it requires database-
specific coding to be done in the middle tier.
4) Thin driver
The thin driver converts JDBC calls directly into the vendor-specific database protocol. That
is why it is known as thin driver. It is fully written in Java language.
Advantages
1. Better performance than all other drivers.
2. No software is required at client side or server side.
Disadvantages
1. Drivers depend on the Database.
Java Database Connectivity with 5 Steps
1. Register the Driver class
2. Create connection
3. Create statement
4. Execute queries
5. Close connection
Servlet
1. Servlet is a technology which is used to create a web application.
2. Servlet is an API that provides many interfaces and classes including documentation.
3. Servlet is an interface that must be implemented for creating any Servlet.
4. Servlet is a class that extends the capabilities of the servers and responds to the incoming
requests. It can respond to any requests.
5. Servlet is a web component that is deployed on the server to create a dynamic web page.
Advantages of Servlet
1. Better performance: because it creates a thread for each request, not process.
2. Portability: because it uses Java language.
3. Robust: JVM manages Servlets, so we don't need to worry about the memory leak,
garbage collection, etc.
4. Secure: because it uses java language.
Servlet Life Cycle
Steps for Servlet execution
1. Servlet class is loaded.
2. Servlet instance is created.
3. init method is invoked.
4. service method is invoked.
5. destroy method is invoked.
HttpServlet Class
The HttpServlet class extends the GenericServlet class and implements Serializable
interface. It provides http specific methods such as doGet, doPost, etc.
Methods of HttpServlet class
There are many methods in HttpServlet class. They are as follows:
1. public void service(ServletRequest req,ServletResponse res)
dispatches the request to the protected service method by converting the request and
response object into http type.
2. protected void service(HttpServletRequest req, HttpServletResponse res)
receives the request from the service method, and dispatches the request to the
method depending on the incoming http request type.
3. protected void doGet(HttpServletRequest req, HttpServletResponse res)
handles the GET request. It is invoked by the web container.
4. protected void doPost(HttpServletRequest req, HttpServletResponse res)
handles the POST request. It is invoked by the web container.
Apache Tomcat Server
1. Apache Tomcat is an open source web server that is developed by Apache software
foundation. It basically make our Java Web applications to run on host and server based
system and it is configured on local host port 8080.
2. Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java
project you can build your WAR (short for Web ARchive) file, and just drop it in the
deploy directory in Tomcat. So basically Apache is an HTTP Server, serving
HTTP. Tomcat is a Servlet and JSP Server serving Java technologies.
IDE’s (Integrated Development Environment)
1. Eclipse
2. MyEclipse
3. NetBeans
4. intelliJ
Database SQL Queries
• INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...); // to insert the data into the database
• SELECT  SELECT * FROM table_name; //to extract all records from database
• WHERE  SELECT column1, column2, ...
FROM table_name
WHERE condition; //to extract record based on some condition
• UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition; //to update columns based on some condition
• DELETE FROM table_name WHERE condition; //to delete particular record
Statement VS PreparedStatement
Cookies in Servlet/JSP
1. A cookie is a small piece of information that is persisted between the multiple client
requests.
2. A cookie has a name, a single value, and optional attributes such as a comment, path and
domain qualifiers, a maximum age, and a version number.
How Cookie works
By default, each request is considered as a new request. In cookies technique, we add cookie
with response from the Servlet/JSP. So cookie is stored in the cache of the browser. After
that if request is sent by the user, cookie is added with request by default. Thus, we
recognize the user as the old user.
Types of Cookie
There are 2 types of cookies in Servlets/JSP.
1. Non-persistent cookie
2. Persistent cookie
1. Non-persistent cookie
It is valid for single session only. It is removed each time when user closes the browser.
2. Persistent cookie
It is valid for multiple session . It is not removed each time when user closes the browser. It
is removed only if user logout.
Advantage of Cookies
1. Simplest technique of maintaining the state.
2. Cookies are maintained at client side.
Disadvantage of Cookies
1. It will not work if cookie is disabled from the browser.
2. Only textual information can be set in Cookie object.
Session in Servlet/JSP
1. Session simply means a particular interval of time.
2. Session Tracking is a way to maintain state (data) of an user. It is also known as session
management.
3. Session is used To recognize the user It is used to recognize the particular user.
HttpSession
Http protocol is a stateless so we need to maintain state using session tracking techniques.
Each time user requests to the server, server treats the request as the new request. So we
need to maintain the state of an user to recognize to particular user.
How to create Session object
The HttpServletRequest interface provides two methods to get the object of HttpSession:
1. public HttpSession getSession(): Returns the current session associated with this
request, or if the request does not have a session, creates one.
2. public HttpSession getSession(boolean create): Returns the current HttpSession
associated with this request or, if there is no current session and create is true, returns a
new session.
Commonly used methods of HttpSession interface
1. public String getId(): Returns a string containing the unique identifier value.
2. public long getCreationTime(): Returns the time when this session was created,
measured in milliseconds.
3. public long getLastAccessedTime(): Returns the last time the client sent a request
associated with this session, as the number of milliseconds.
4. public void invalidate(): Invalidates this session then unbinds any objects bound to it.

More Related Content

PDF
Java servlets
PPTX
java Servlet technology
PPTX
Java/Servlet/JSP/JDBC
PPTX
PPTX
PPTX
Java Servlets
PDF
JDBC in Servlets
PPT
Java Servlet
Java servlets
java Servlet technology
Java/Servlet/JSP/JDBC
Java Servlets
JDBC in Servlets
Java Servlet

What's hot (20)

PPT
1 java servlets and jsp
PPTX
Session And Cookies In Servlets - Java
PPTX
Servlets
PPTX
Servlet.ppt
PPT
Java Servlets
PDF
Java EE 01-Servlets and Containers
PPTX
Enterprise java unit-1_chapter-3
PPT
Servlet ppt by vikas jagtap
PPTX
Servlets & jdbc
PDF
PPT
An Introduction To Java Web Technology
PPT
Java Servlets
PPT
Java - Servlet - Mazenet Solution
PPTX
Javax.servlet,http packages
PPTX
Chapter 3 servlet & jsp
PPTX
Servlets
DOC
Java Servlets & JSP
PDF
java servlet and servlet programming
PPTX
Enterprise java unit-2_chapter-3
1 java servlets and jsp
Session And Cookies In Servlets - Java
Servlets
Servlet.ppt
Java Servlets
Java EE 01-Servlets and Containers
Enterprise java unit-1_chapter-3
Servlet ppt by vikas jagtap
Servlets & jdbc
An Introduction To Java Web Technology
Java Servlets
Java - Servlet - Mazenet Solution
Javax.servlet,http packages
Chapter 3 servlet & jsp
Servlets
Java Servlets & JSP
java servlet and servlet programming
Enterprise java unit-2_chapter-3
Ad

Similar to Advanced java+JDBC+Servlet (20)

PDF
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
PPTX
UNIT - 5.pptx Servlets And Database Connectivity
PPT
session and cookies.ppt
PPTX
CS8651 IP Unit 3.pptx
PDF
Bt0083 server side programing
PPTX
Advance Java Topics (J2EE)
PPTX
servlets sessions and cookies, jdbc connectivity
PPT
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
PPT
Servlet (1) also contains code to create it.ppt
DOCX
It and ej
PPT
Servlet1.ppt
PPT
Servlet.ppt
PPT
Servlet.ppt
PPTX
Servlets-UNIT3and introduction to servlet
PPTX
AJppt.pptx
PPTX
SERVIET
PPTX
Advance Java
DOCX
Server side programming bt0083
DOCX
Major project report
PPTX
J2EE : Java servlet and its types, environment
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
UNIT - 5.pptx Servlets And Database Connectivity
session and cookies.ppt
CS8651 IP Unit 3.pptx
Bt0083 server side programing
Advance Java Topics (J2EE)
servlets sessions and cookies, jdbc connectivity
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
Servlet (1) also contains code to create it.ppt
It and ej
Servlet1.ppt
Servlet.ppt
Servlet.ppt
Servlets-UNIT3and introduction to servlet
AJppt.pptx
SERVIET
Advance Java
Server side programming bt0083
Major project report
J2EE : Java servlet and its types, environment
Ad

More from Anuj Singh Rajput (20)

PPTX
Web technology
PPTX
Java script
PPTX
Html (hypertext markup language)
PPTX
PPTX
Jsp session 13
PPTX
Jsp session 12
PPTX
Jsp session 11
PPTX
Jsp session 10
PPTX
Jsp session 9
PPTX
Jsp session 8
PPTX
Jsp session 7
PPTX
Jsp session 6
PPTX
Jsp session 5
PPTX
Jsp session 4
PPTX
Jsp session 3
PPTX
Jsp session 2
PPTX
Jsp session 1
PPTX
Servlet session 14
PPTX
Servlet session 13
Web technology
Java script
Html (hypertext markup language)
Jsp session 13
Jsp session 12
Jsp session 11
Jsp session 10
Jsp session 9
Jsp session 8
Jsp session 7
Jsp session 6
Jsp session 5
Jsp session 4
Jsp session 3
Jsp session 2
Jsp session 1
Servlet session 14
Servlet session 13

Recently uploaded (20)

PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Microbial diseases, their pathogenesis and prophylaxis
Anesthesia in Laparoscopic Surgery in India
2.FourierTransform-ShortQuestionswithAnswers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Yogi Goddess Pres Conference Studio Updates
Abdominal Access Techniques with Prof. Dr. R K Mishra
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Final Presentation General Medicine 03-08-2024.pptx
Complications of Minimal Access Surgery at WLH
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
VCE English Exam - Section C Student Revision Booklet
STATICS OF THE RIGID BODIES Hibbelers.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025

Advanced java+JDBC+Servlet

  • 2. JDBC (Java DataBase Connectivity) There are four types of JDBC drivers: 1. JDBC-ODBC Bridge Driver 2. Native Driver 3. Network Protocol Driver 4. Thin Driver
  • 3. 1) JDBC-ODBC bridge driver The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function calls. This is now discouraged because of thin driver.
  • 4. Advantages 1. easy to use. 2. can be easily connected to any database. Disadvantages 1. Performance degraded because JDBC method call is converted into the ODBC function calls. 2. The ODBC driver needs to be installed on the client machine. 2. Native-API driver The Native API driver uses the client-side libraries of the database. The driver converts JDBC method calls into native calls of the database API. It is not written entirely in java.
  • 5. Advantages 1. performance upgraded than JDBC-ODBC bridge driver. Disadvantages 1. The Native driver needs to be installed on the each client machine. 2. The Vendor client library needs to be installed on client machine.
  • 6. 3) Network Protocol driver The Network Protocol driver uses middleware (application server) that converts JDBC calls directly or indirectly into the vendor-specific database protocol. It is fully written in java.
  • 7. Advantages 1. No client side library is required because of application server that can perform many tasks like auditing, load balancing, logging etc.. Disadvantages 1. Network support is required on client machine. 2. Requires database-specific coding to be done in the middle tier. 3. Maintenance of Network Protocol driver becomes costly because it requires database- specific coding to be done in the middle tier. 4) Thin driver The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is why it is known as thin driver. It is fully written in Java language.
  • 8. Advantages 1. Better performance than all other drivers. 2. No software is required at client side or server side. Disadvantages 1. Drivers depend on the Database.
  • 9. Java Database Connectivity with 5 Steps 1. Register the Driver class 2. Create connection 3. Create statement 4. Execute queries 5. Close connection
  • 10. Servlet 1. Servlet is a technology which is used to create a web application. 2. Servlet is an API that provides many interfaces and classes including documentation. 3. Servlet is an interface that must be implemented for creating any Servlet. 4. Servlet is a class that extends the capabilities of the servers and responds to the incoming requests. It can respond to any requests. 5. Servlet is a web component that is deployed on the server to create a dynamic web page.
  • 11. Advantages of Servlet 1. Better performance: because it creates a thread for each request, not process. 2. Portability: because it uses Java language. 3. Robust: JVM manages Servlets, so we don't need to worry about the memory leak, garbage collection, etc. 4. Secure: because it uses java language.
  • 13. Steps for Servlet execution 1. Servlet class is loaded. 2. Servlet instance is created. 3. init method is invoked. 4. service method is invoked. 5. destroy method is invoked.
  • 14. HttpServlet Class The HttpServlet class extends the GenericServlet class and implements Serializable interface. It provides http specific methods such as doGet, doPost, etc. Methods of HttpServlet class There are many methods in HttpServlet class. They are as follows: 1. public void service(ServletRequest req,ServletResponse res) dispatches the request to the protected service method by converting the request and response object into http type. 2. protected void service(HttpServletRequest req, HttpServletResponse res) receives the request from the service method, and dispatches the request to the method depending on the incoming http request type. 3. protected void doGet(HttpServletRequest req, HttpServletResponse res) handles the GET request. It is invoked by the web container. 4. protected void doPost(HttpServletRequest req, HttpServletResponse res) handles the POST request. It is invoked by the web container.
  • 15. Apache Tomcat Server 1. Apache Tomcat is an open source web server that is developed by Apache software foundation. It basically make our Java Web applications to run on host and server based system and it is configured on local host port 8080. 2. Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat. So basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java technologies.
  • 16. IDE’s (Integrated Development Environment) 1. Eclipse 2. MyEclipse 3. NetBeans 4. intelliJ Database SQL Queries • INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); // to insert the data into the database • SELECT  SELECT * FROM table_name; //to extract all records from database • WHERE  SELECT column1, column2, ... FROM table_name WHERE condition; //to extract record based on some condition • UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition; //to update columns based on some condition • DELETE FROM table_name WHERE condition; //to delete particular record
  • 18. Cookies in Servlet/JSP 1. A cookie is a small piece of information that is persisted between the multiple client requests. 2. A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number. How Cookie works By default, each request is considered as a new request. In cookies technique, we add cookie with response from the Servlet/JSP. So cookie is stored in the cache of the browser. After that if request is sent by the user, cookie is added with request by default. Thus, we recognize the user as the old user. Types of Cookie There are 2 types of cookies in Servlets/JSP. 1. Non-persistent cookie 2. Persistent cookie
  • 19. 1. Non-persistent cookie It is valid for single session only. It is removed each time when user closes the browser. 2. Persistent cookie It is valid for multiple session . It is not removed each time when user closes the browser. It is removed only if user logout. Advantage of Cookies 1. Simplest technique of maintaining the state. 2. Cookies are maintained at client side. Disadvantage of Cookies 1. It will not work if cookie is disabled from the browser. 2. Only textual information can be set in Cookie object.
  • 20. Session in Servlet/JSP 1. Session simply means a particular interval of time. 2. Session Tracking is a way to maintain state (data) of an user. It is also known as session management. 3. Session is used To recognize the user It is used to recognize the particular user. HttpSession Http protocol is a stateless so we need to maintain state using session tracking techniques. Each time user requests to the server, server treats the request as the new request. So we need to maintain the state of an user to recognize to particular user.
  • 21. How to create Session object The HttpServletRequest interface provides two methods to get the object of HttpSession: 1. public HttpSession getSession(): Returns the current session associated with this request, or if the request does not have a session, creates one. 2. public HttpSession getSession(boolean create): Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.
  • 22. Commonly used methods of HttpSession interface 1. public String getId(): Returns a string containing the unique identifier value. 2. public long getCreationTime(): Returns the time when this session was created, measured in milliseconds. 3. public long getLastAccessedTime(): Returns the last time the client sent a request associated with this session, as the number of milliseconds. 4. public void invalidate(): Invalidates this session then unbinds any objects bound to it.