SlideShare a Scribd company logo
IT3401 Web Essentials
Unit V – Servlets and Database Connectivity
Unit IV – Servlets and Database Connectivity
Servlets: Java Servlet Architecture – Servlet Life cycle
– Form GET and POST actions – Sessions – Cookies –
Database connectivity – JDBC – Creation of simple
interactive applications – Simple database applications
Servlets – Introduction
• Servlet technology is used to create a web application (resides at server side and
generates a dynamic web page).
• Servlets are the Java programs that run on the Java-enabled web server or
application server.
• They are used to handle the request obtained from the webserver, process the
request, produce the response, then send a response back to the webserver.
• Properties:
• Servlets work on the server-side.
• Servlets are capable of handling complex requests obtained from the
webserver.
Java Servlet Architecture
Execution of Servlets basically involves six basic steps:
1. The clients send the request to the webserver.
2. The web server receives the request.
3. The web server passes the request to the corresponding servlet.
4. The servlet processes the request and generates the response in the form of
output.
5. The servlet sends the response back to the webserver.
6. The web server sends the response back to the client and the client browser
displays it on the screen.
Java Servlet Architecture
Java Servlet Architecture
• Client: It sends HTTP requests over to the web server and again processing
the response it gets back from the server.
• Web Server: Primary job of a web server is to process the requests and
responses that a user sends over time and maintain how a web user would
be able to access the files that has been hosted over the server. The server is
a software which manages access to a centralized resource or service in a
network.. There are precisely two types of webservers:
– Static web server
– Dynamic web server
Java Servlet Architecture
• Web Container: A component in servlet architecture which is responsible
for communicating with the servlets. Two prime tasks of a web container
are:
– Managing the servlet lifecycle
– URL mapping
Web container sits at the server-side managing and handling all the requests
that are coming in either from the servlets or from some JSP pages or
potentially any other file system.
Java Servlet Architecture
Types of Servlets:
• Generic Servlets
• HTTP Servlets
To create a Servlet:
1. Implementing Servlet Interface
2. Extending Generic Servlet
3. Extending HTTP Servlet
Java Servlet Architecture
CGI (Common Gateway Interface)
• CGI technology enables the web server to call an external program and pass HTTP request
information to the external program to process the request.
• For each request, it starts a new process.
Disadvantages
• If the number of clients increases, it takes more time for sending the response.
• For each request, it starts a process, and the web server is limited to start processes.
• It uses platform dependent language e.g. C, C++, perl.
Java Servlet Architecture
Advantages of Servlet
• The web container creates threads for handling the multiple requests to the Servlet.
• Threads have many benefits over the Processes such as they share a common
memory area, lightweight, cost of communication between the threads are low.
• Advantages: Better performance, Portability, Robust, Secure.
Java Servlet Architecture
Website: static vs
dynamic
A collection of related web pages that may contain text, images,
audio and video.
HTTP
The data communication protocol
communication between client and server.
used to establish
HTTP Requests
The request send by the computer to a web server that contains
all sorts of potentially interesting information.
Get vs Post It gives the difference between GET and POST request.
Container
Used in java for dynamically generating the web pages on the
server side.
Server: Web
Application
vs Used to manage the network resources and for running the
program or software that provides services.
Content Type
HTTP header that provides the description about what are you
sending to the browser.
Servlet Life Cycle
• The entire life cycle of a Servlet is managed by the Servlet container which uses
the javax.servlet.
• Stages of the Servlet Life Cycle:
• Loading a Servlet: Loading and initializing the Servlet by the Servlet container
• Initializing the Servlet: After the Servlet is instantiated successfully, the
Servlet container initializes the instantiated Servlet object. The container
initializes the Servlet object by invoking the Servlet.init(ServletConfig) method
• Request handling: It creates the ServletRequest and ServletResponse objects.
• Destroying the Servlet: When a Servlet container decides to destroy the Servlet
Servlet Life Cycle
Servlet Life Cycle
Servlet Life Cycle Methods
• init(): The Servlet.init() method is called by the Servlet container to
indicate that this Servlet instance is instantiated successfully and is about to
put into service.
• service(): It is invoked to inform the Servlet about the client requests.
• destroy(): It runs only once during the lifetime of a Servlet and signals the
end of the Servlet instance.
Servlet Life Cycle
Servlet Life Cycle Methods
Form GET and POST Actions
GET Method
• The GET method sends the encoded user information appended to the page request.
• The page and the encoded information are separated by the ? (question mark)
symbol.
• The GET method is the default method to pass information from browser to web
server.
• The GET method has size limitation: only 1024 characters can be used in a request
string.
• Servlet handles this type of requests using doGet() method.
• Example
http://www.test.com/hello?key1 = value1&key2 = value2
Form GET and POST Actions
POST Method
• More reliable method of passing information to a backend program is the POST
method.
• This packages the information in exactly the same way as GET method, but instead
of sending it as a text string after a ? (question mark) in the URL it sends it as a
separate message.
• Servlet handles this type of requests using doPost() method.
Form GET and POST Actions
Reading Form Data Using Servlet
• getParameter() − Call request.getParameter() method to get the value of a form
parameter.
• getParameterValues() − Call this method if the parameter appears more than once
and returns multiple values, for example checkbox.
• getParameterNames() − Call this method if you want a complete list of all
parameters in the current request.
Sessions
• Session Tracking is a way to maintain state (data) of an user. It is also
known as session management in servlet.
• Http protocol is a stateless so it is needed 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.
• HTTP is stateless that means each request is considered as the new request.
Sessions
Sessions
Session Tracking Techniques: There are four techniques used in Session
tracking:
1. Cookies
2. Hidden Form Field
3. URL Rewriting
4. HttpSession
Cookies
• A cookie is a small piece of information that is persisted between the
multiple client requests.
• 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.
Types of Cookie
• Non-persistent cookie: It is valid for single session only. It is removed
each time when user closes the browser.
• 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 or
signout.
Cookies
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.
Cookies
Cookie class
• javax.servlet.http.Cookie class provides the functionality
cookies. It provides a lot of useful methods for cookies.
of using
Constructor of Cookie class
Constructor Description
Cookie() constructs a cookie.
Cookie(String name, String value) constructs a cookie with a
specified name and value.
Cookies
Methods of Cookie class
Method Description
public void setMaxAge(int
expiry)
Sets the maximum age of the cookie in
seconds.
public String getName() Returns the name of the cookie. The
name cannot be changed after creation.
public String getValue() Returns the value of the cookie.
public void setName(String name) changes the name of the cookie.
public void setValue(String value) changes the value of the cookie.
Database Connectivity - JDBC
• JDBC stands for Java Database Connectivity.
• JDBC is a Java API to connect and execute the query with the database.
Database Connectivity - JDBC
• The java.sql package contains classes and interfaces for JDBC API.
• A list of popular interfaces of JDBC API are given below:
• Driver interface
• Connection interface
• Statement interface
• PreparedStatement interface
• CallableStatement interface
• ResultSet interface
• ResultSetMetaData interface
• DatabaseMetaData interface
• RowSet interface
Database Connectivity - JDBC
• A list of popular classes of JDBC API are given below:
• DriverManager class
• Blob class
• Clob class
• Types class
• One 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.
Database Connectivity - JDBC
Database Connectivity - JDBC
Steps in JDBC
• Register the Driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
• Create connection
Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:
1521:xe","system","password");
• Create statement
Statement stmt=con.createStatement();
Database Connectivity - JDBC
Steps in JDBC
• Execute queries
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next()){
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
• Close connection
con.close();

More Related Content

PPTX
WEB TECHNOLOGY Unit-3.pptx
PPTX
Servlets-UNIT3and introduction to servlet
PPTX
21CS642 Module 4_1 Servlets PPT.pptx VI SEM CSE Students
PPTX
IP UNIT III PPT.pptx
PPTX
CS8651 IP Unit 3.pptx
PPT
Module 4.pptModule 4.pptModule 4.pptModule 4.ppt
PPTX
Servlet.pptx
PPTX
Servlet.pptx
WEB TECHNOLOGY Unit-3.pptx
Servlets-UNIT3and introduction to servlet
21CS642 Module 4_1 Servlets PPT.pptx VI SEM CSE Students
IP UNIT III PPT.pptx
CS8651 IP Unit 3.pptx
Module 4.pptModule 4.pptModule 4.pptModule 4.ppt
Servlet.pptx
Servlet.pptx

Similar to UNIT - 5.pptx Servlets And Database Connectivity (20)

PPTX
servlets sessions and cookies, jdbc connectivity
PPT
session and cookies.ppt
PPTX
Servlets api overview
PPTX
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
PPT
PDF
Lecture 2: Servlets
PPT
Ppt for Online music store
PPT
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
PPT
Servlet.ppt
PPT
Servlet.ppt
PPT
Servlet1.ppt
PPT
Servlet (1) also contains code to create it.ppt
PPTX
java Servlet technology
PDF
Liit tyit sem 5 enterprise java unit 1 notes 2018
PDF
Servlet and JSP
PPTX
BITM3730Week12.pptx
PDF
Servlet classnotes
PPT
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
PDF
Adv java unit 4 M.Sc CS.pdf
PPTX
UNIT-3 Servlet
servlets sessions and cookies, jdbc connectivity
session and cookies.ppt
Servlets api overview
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
Lecture 2: Servlets
Ppt for Online music store
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
Servlet.ppt
Servlet.ppt
Servlet1.ppt
Servlet (1) also contains code to create it.ppt
java Servlet technology
Liit tyit sem 5 enterprise java unit 1 notes 2018
Servlet and JSP
BITM3730Week12.pptx
Servlet classnotes
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
Adv java unit 4 M.Sc CS.pdf
UNIT-3 Servlet
Ad

More from bmit1 (20)

PPTX
AI-PoweJHJKJGJUJUUYKUKUKYUKYUKYUred Cybersecurity.pptx
PPTX
Creative innovation award certificate.pptx
PPT
PPT presentationhjvfitudtyicfuys7erstodxfciuggguys Phd.ppt
PPT
PPT pretdrtserstraswteateustrsentations Phd.ppt
PPTX
ICEATsssefggfdrghhkoolknvdesfjonbeeffd0.pptx
PPTX
ICEAT25043457uiifghjnnbdddfghhjnkkkkj0.pptx
PPT
BechYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYstein.ppt
PPT
shoemakerRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR.ppt
PPTX
INDUSTRY 4.0000000000000000000000000000000000000.pptx
PPTX
INTERNET OF THINGSSSSSSSSSSSSSSSSSSSSSSSSS.pptx
PPTX
SUBEDUCATIONNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN-PP...
PPTX
KIOT_DIV_Full Stack Vertical_Presentation_v0.1.pptx
PPTX
basiccomputerorganization-160726065251.pptx
PPTX
TLPpppppppppppppppppppppppppppresentation.pptx
PPTX
UNIT 2 - PYTHON FOR DATASCIENCE UNDER PROCEESING DATA .pptx
PPTX
Evaluation Reforms Osmania University.pptx
PPTX
Unit 2.7 PN junction diode & breakdown.pptx
PPTX
Unit 2.8 Metal-Semiconductor contact (1).pptx
PPTX
computer networksssssssssssssssssssssssssssss.pptx
PPTX
how to write a paper -2011151911324429.pptx
AI-PoweJHJKJGJUJUUYKUKUKYUKYUKYUred Cybersecurity.pptx
Creative innovation award certificate.pptx
PPT presentationhjvfitudtyicfuys7erstodxfciuggguys Phd.ppt
PPT pretdrtserstraswteateustrsentations Phd.ppt
ICEATsssefggfdrghhkoolknvdesfjonbeeffd0.pptx
ICEAT25043457uiifghjnnbdddfghhjnkkkkj0.pptx
BechYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYstein.ppt
shoemakerRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR.ppt
INDUSTRY 4.0000000000000000000000000000000000000.pptx
INTERNET OF THINGSSSSSSSSSSSSSSSSSSSSSSSSS.pptx
SUBEDUCATIONNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN-PP...
KIOT_DIV_Full Stack Vertical_Presentation_v0.1.pptx
basiccomputerorganization-160726065251.pptx
TLPpppppppppppppppppppppppppppresentation.pptx
UNIT 2 - PYTHON FOR DATASCIENCE UNDER PROCEESING DATA .pptx
Evaluation Reforms Osmania University.pptx
Unit 2.7 PN junction diode & breakdown.pptx
Unit 2.8 Metal-Semiconductor contact (1).pptx
computer networksssssssssssssssssssssssssssss.pptx
how to write a paper -2011151911324429.pptx
Ad

Recently uploaded (20)

PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
01-Introduction-to-Information-Management.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Cell Types and Its function , kingdom of life
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Business Ethics Teaching Materials for college
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
master seminar digital applications in india
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
2.FourierTransform-ShortQuestionswithAnswers.pdf
Complications of Minimal Access Surgery at WLH
VCE English Exam - Section C Student Revision Booklet
01-Introduction-to-Information-Management.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Cell Types and Its function , kingdom of life
human mycosis Human fungal infections are called human mycosis..pptx
Business Ethics Teaching Materials for college
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Cell Structure & Organelles in detailed.
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Week 4 Term 3 Study Techniques revisited.pptx
Anesthesia in Laparoscopic Surgery in India
master seminar digital applications in india
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Pharma ospi slides which help in ospi learning
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
O7-L3 Supply Chain Operations - ICLT Program
102 student loan defaulters named and shamed – Is someone you know on the list?

UNIT - 5.pptx Servlets And Database Connectivity

  • 1. IT3401 Web Essentials Unit V – Servlets and Database Connectivity
  • 2. Unit IV – Servlets and Database Connectivity Servlets: Java Servlet Architecture – Servlet Life cycle – Form GET and POST actions – Sessions – Cookies – Database connectivity – JDBC – Creation of simple interactive applications – Simple database applications
  • 3. Servlets – Introduction • Servlet technology is used to create a web application (resides at server side and generates a dynamic web page). • Servlets are the Java programs that run on the Java-enabled web server or application server. • They are used to handle the request obtained from the webserver, process the request, produce the response, then send a response back to the webserver. • Properties: • Servlets work on the server-side. • Servlets are capable of handling complex requests obtained from the webserver.
  • 4. Java Servlet Architecture Execution of Servlets basically involves six basic steps: 1. The clients send the request to the webserver. 2. The web server receives the request. 3. The web server passes the request to the corresponding servlet. 4. The servlet processes the request and generates the response in the form of output. 5. The servlet sends the response back to the webserver. 6. The web server sends the response back to the client and the client browser displays it on the screen.
  • 6. Java Servlet Architecture • Client: It sends HTTP requests over to the web server and again processing the response it gets back from the server. • Web Server: Primary job of a web server is to process the requests and responses that a user sends over time and maintain how a web user would be able to access the files that has been hosted over the server. The server is a software which manages access to a centralized resource or service in a network.. There are precisely two types of webservers: – Static web server – Dynamic web server
  • 7. Java Servlet Architecture • Web Container: A component in servlet architecture which is responsible for communicating with the servlets. Two prime tasks of a web container are: – Managing the servlet lifecycle – URL mapping Web container sits at the server-side managing and handling all the requests that are coming in either from the servlets or from some JSP pages or potentially any other file system.
  • 8. Java Servlet Architecture Types of Servlets: • Generic Servlets • HTTP Servlets To create a Servlet: 1. Implementing Servlet Interface 2. Extending Generic Servlet 3. Extending HTTP Servlet
  • 9. Java Servlet Architecture CGI (Common Gateway Interface) • CGI technology enables the web server to call an external program and pass HTTP request information to the external program to process the request. • For each request, it starts a new process. Disadvantages • If the number of clients increases, it takes more time for sending the response. • For each request, it starts a process, and the web server is limited to start processes. • It uses platform dependent language e.g. C, C++, perl.
  • 10. Java Servlet Architecture Advantages of Servlet • The web container creates threads for handling the multiple requests to the Servlet. • Threads have many benefits over the Processes such as they share a common memory area, lightweight, cost of communication between the threads are low. • Advantages: Better performance, Portability, Robust, Secure.
  • 11. Java Servlet Architecture Website: static vs dynamic A collection of related web pages that may contain text, images, audio and video. HTTP The data communication protocol communication between client and server. used to establish HTTP Requests The request send by the computer to a web server that contains all sorts of potentially interesting information. Get vs Post It gives the difference between GET and POST request. Container Used in java for dynamically generating the web pages on the server side. Server: Web Application vs Used to manage the network resources and for running the program or software that provides services. Content Type HTTP header that provides the description about what are you sending to the browser.
  • 12. Servlet Life Cycle • The entire life cycle of a Servlet is managed by the Servlet container which uses the javax.servlet. • Stages of the Servlet Life Cycle: • Loading a Servlet: Loading and initializing the Servlet by the Servlet container • Initializing the Servlet: After the Servlet is instantiated successfully, the Servlet container initializes the instantiated Servlet object. The container initializes the Servlet object by invoking the Servlet.init(ServletConfig) method • Request handling: It creates the ServletRequest and ServletResponse objects. • Destroying the Servlet: When a Servlet container decides to destroy the Servlet
  • 14. Servlet Life Cycle Servlet Life Cycle Methods • init(): The Servlet.init() method is called by the Servlet container to indicate that this Servlet instance is instantiated successfully and is about to put into service. • service(): It is invoked to inform the Servlet about the client requests. • destroy(): It runs only once during the lifetime of a Servlet and signals the end of the Servlet instance.
  • 15. Servlet Life Cycle Servlet Life Cycle Methods
  • 16. Form GET and POST Actions GET Method • The GET method sends the encoded user information appended to the page request. • The page and the encoded information are separated by the ? (question mark) symbol. • The GET method is the default method to pass information from browser to web server. • The GET method has size limitation: only 1024 characters can be used in a request string. • Servlet handles this type of requests using doGet() method. • Example http://www.test.com/hello?key1 = value1&key2 = value2
  • 17. Form GET and POST Actions POST Method • More reliable method of passing information to a backend program is the POST method. • This packages the information in exactly the same way as GET method, but instead of sending it as a text string after a ? (question mark) in the URL it sends it as a separate message. • Servlet handles this type of requests using doPost() method.
  • 18. Form GET and POST Actions Reading Form Data Using Servlet • getParameter() − Call request.getParameter() method to get the value of a form parameter. • getParameterValues() − Call this method if the parameter appears more than once and returns multiple values, for example checkbox. • getParameterNames() − Call this method if you want a complete list of all parameters in the current request.
  • 19. Sessions • Session Tracking is a way to maintain state (data) of an user. It is also known as session management in servlet. • Http protocol is a stateless so it is needed 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. • HTTP is stateless that means each request is considered as the new request.
  • 21. Sessions Session Tracking Techniques: There are four techniques used in Session tracking: 1. Cookies 2. Hidden Form Field 3. URL Rewriting 4. HttpSession
  • 22. Cookies • A cookie is a small piece of information that is persisted between the multiple client requests. • 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. Types of Cookie • Non-persistent cookie: It is valid for single session only. It is removed each time when user closes the browser. • 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 or signout.
  • 23. Cookies 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.
  • 24. Cookies Cookie class • javax.servlet.http.Cookie class provides the functionality cookies. It provides a lot of useful methods for cookies. of using Constructor of Cookie class Constructor Description Cookie() constructs a cookie. Cookie(String name, String value) constructs a cookie with a specified name and value.
  • 25. Cookies Methods of Cookie class Method Description public void setMaxAge(int expiry) Sets the maximum age of the cookie in seconds. public String getName() Returns the name of the cookie. The name cannot be changed after creation. public String getValue() Returns the value of the cookie. public void setName(String name) changes the name of the cookie. public void setValue(String value) changes the value of the cookie.
  • 26. Database Connectivity - JDBC • JDBC stands for Java Database Connectivity. • JDBC is a Java API to connect and execute the query with the database.
  • 27. Database Connectivity - JDBC • The java.sql package contains classes and interfaces for JDBC API. • A list of popular interfaces of JDBC API are given below: • Driver interface • Connection interface • Statement interface • PreparedStatement interface • CallableStatement interface • ResultSet interface • ResultSetMetaData interface • DatabaseMetaData interface • RowSet interface
  • 28. Database Connectivity - JDBC • A list of popular classes of JDBC API are given below: • DriverManager class • Blob class • Clob class • Types class • One 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.
  • 30. Database Connectivity - JDBC Steps in JDBC • Register the Driver class Class.forName("oracle.jdbc.driver.OracleDriver"); • Create connection Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@localhost: 1521:xe","system","password"); • Create statement Statement stmt=con.createStatement();
  • 31. Database Connectivity - JDBC Steps in JDBC • Execute queries ResultSet rs=stmt.executeQuery("select * from emp"); while(rs.next()){ System.out.println(rs.getInt(1)+" "+rs.getString(2)); } • Close connection con.close();