SlideShare a Scribd company logo
Presented by:
Akanksha Shukla
 Introduction
JSP pages
Markup
Scriptlets
Example
 Accessing Database From JSP Page
Steps to access database
Example
Description
 References
2
Java Server Pages (JSP) is a Java technology
that helps software developers serve dynamically
generated web pages based on HTML, XML, or
other document types. JSP pages are loaded in the
server and operated from a structured special
installed Java server packet called a Java EE Web
Application, often packaged as a .war or .ear file
archive. JSP allows Java code and certain pre-
defined actions to be interleaved with static web
markup content, with the resulting page being
compiled and executed on the server to deliver an
HTML or XML document.
.
3
4
JSP allows Java code and certain pre-defined
actions to be interleaved with static web
markup content, with the resulting page
being compiled and executed on the server to
deliver an HTML or XML document.
JSP syntax is a fluid mix of two basic content
forms:
 1. Scriptlet Elements
 2. Markup
Markup is typically standard HTML or XML.
When the page is requested, the Java code is
executed and its output is added with the
surrounding markup to create the final page.
Because Java is a compiled language, not a
scripting language, JSP pages must be compiled
to Java bytecode classes before they can be
executed, but such compilation is needed only
when a change to the source JSP file has
occurred.
5
Scriptlet elements are delimited blocks of Java
code which may be intermixed with the
markup. Java code is not required to be
complete (self contained) within its scriptlet
element block, but can straddle markup
content providing the page as a whole is
syntactically correct (for example, any Java
if/for/while blocks opened in one scriptlet
element must be correctly closed in a later
element for the page to successfully compile).
6
7
Request
JSP Engine
and
Web Server
JSP file
Component
Client
Response
Request Request
Response Response
Fig: Data Passed b/w Client & Server
 <%-- use the 'taglib' directive to make the JSTL 1.0 core tags available; use the uri
 "http://java.sun.com/jsp/jstl/core" for JSTL 1.1 --%>
 <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

 <%-- use the 'jsp:useBean' standard action to create the Date object; the object is set
 as an attribute in page scope
 --%>
 <jsp:useBean id="date" class="java.util.Date" />

 <html>
 <head><title>First JSP</title></head>
 <body>
 <h2>Here is today's date</h2>
 <c:out value="${date}" />
 </body>
 </html>
8
9
While accessing JSP database from JSP page, we
should have some database package
installed. Here we consider the connectivity
from MYSQL database with JSP.
Assumptions:
 TOMCAT web server is installed.
 MYSQL server is installed.
 JDK is installed.
Various steps are:
1. Create a database named “books”, statement is:
MYSQL>CREATE DATABASE books ;
2. Create a table named “books_details”, statement is:
MYSQL>CREATE TABLE books_details (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`book_name` VARCHAR( 100 ) NOT NULL ,
`author` VARCHAR( 100 ) NOT NULL ,
PRIMARY KEY ( `id` )
)
10
11
The table is:
ID Book Name Author
1. Java I/O Tim Ritchey
2. Java & XML,
2 Edition Brett McLaughlin
3. Java Swing,
2nd Edition Dave Wood, Marc Loy,
3. Copy the MYSQL-connector-java-3.1.14-
bin.jar to the C:tomcat_directorycommonlib.
Then set the Classpath. For that, we have to
perform the following:
Control Panel->System-> System Properties->
Environmental Variables and set Classpath.
12
13
4. After setting Classpath, restart the Tomcat
Web Server using the startup.bat file at the
command promt.
Create a folder DBDemo using following line:
C:tomcat_directoryjsp-examplesDBDemo
and now write the JSP program which is used
to connect the database.
14
<%@ page language="java" import="java.sql.*"
%>
<%
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
String driver = "org.gjt.mm.mysql.Driver";
Class.forName(driver).newInstance();
Classes &
interfaces
object
instantiation
try
{
String url=
"jdbc:mysql://localhost/books?user=
<user>&password=<password>";
con=DriverManager.getConnection(url);
stmt=con.createStatement();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
15
16
if(request.getParameter("action") != null)
{
String book=
request.getParameter("bookname");
String author=request.getParameter("author");
stmt.executeUpdate("insert into
books_details(book_name, author)
values('"+bookname+"','"+author+"')");
rst=stmt.executeQuery("select * from
books_details");
%>
Retrieve fields
while(rst.next())
{%>
<tr><td><%=no%></td>
<td><%=rst.getString(“book_name")%> </td>
<td> <%=rst.getString("author“)%> </td>
</tr>
<%no++;
}
rst.close();
stmt.close();
con.close();
%>
17
1. JSP is a kind of scripting language in which we can
embed JAVA code along with HTML elements.
2. Above code of JDBC and jsp shows how we can
manipulate data in a relational database from JSP page.
We need to use the java.sql package: DriverManager,
Connection, Statement, and ResultSet. To create a Web
application, we need JDBC to use more features such as
prepared statements and connection pooling.
18
 Figures- http://www.google.co.in
 “Web Technology” by A.A.Puntambekar
 http://www.wikipedia.org
19
Queries
??? 20
Thanking to
you all......
21

More Related Content

What's hot

Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
1. java database connectivity (jdbc)
1. java database connectivity (jdbc)1. java database connectivity (jdbc)
1. java database connectivity (jdbc)
Fad Zulkifli
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
Ranjan Kumar
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
Lecture 1. java database connectivity
Lecture 1. java database connectivityLecture 1. java database connectivity
Lecture 1. java database connectivity
Waheedullah Suliman Khail
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
Nuha Noor
 
java jdbc connection
java jdbc connectionjava jdbc connection
java jdbc connection
Waheed Warraich
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
Tanmoy Barman
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
Vikas Jagtap
 
Overview Of JDBC
Overview Of JDBCOverview Of JDBC
Overview Of JDBC
Mindfire Solutions
 
Database Access With JDBC
Database Access With JDBCDatabase Access With JDBC
Database Access With JDBC
Dharani Kumar Madduri
 
Jdbc connectivity
Jdbc connectivityJdbc connectivity
Jdbc connectivity
arikazukito
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
Pooja Talreja
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivitybackdoor
 
Jdbc connectivity in java
Jdbc connectivity in javaJdbc connectivity in java
Jdbc connectivity in java
Muthukumaran Subramanian
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
Mazenetsolution
 

What's hot (20)

Jdbc
JdbcJdbc
Jdbc
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
1. java database connectivity (jdbc)
1. java database connectivity (jdbc)1. java database connectivity (jdbc)
1. java database connectivity (jdbc)
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Lecture 1. java database connectivity
Lecture 1. java database connectivityLecture 1. java database connectivity
Lecture 1. java database connectivity
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
 
java jdbc connection
java jdbc connectionjava jdbc connection
java jdbc connection
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Overview Of JDBC
Overview Of JDBCOverview Of JDBC
Overview Of JDBC
 
Database Access With JDBC
Database Access With JDBCDatabase Access With JDBC
Database Access With JDBC
 
JDBC
JDBCJDBC
JDBC
 
Jdbc connectivity
Jdbc connectivityJdbc connectivity
Jdbc connectivity
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc connectivity in java
Jdbc connectivity in javaJdbc connectivity in java
Jdbc connectivity in java
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
 

Viewers also liked

Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
Java server pages
Java server pagesJava server pages
Java server pages
Tanmoy Barman
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
chakrapani tripathi
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
kamal kotecha
 
Video Streaming - 4.ppt
Video Streaming - 4.pptVideo Streaming - 4.ppt
Video Streaming - 4.pptVideoguy
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
Darshit Metaliya
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
APSMIND TECHNOLOGY PVT LTD.
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
kamal kotecha
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
 

Viewers also liked (13)

JSP
JSPJSP
JSP
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Losseless
LosselessLosseless
Losseless
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
 
Video Streaming - 4.ppt
Video Streaming - 4.pptVideo Streaming - 4.ppt
Video Streaming - 4.ppt
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Compression
CompressionCompression
Compression
 

Similar to DataBase Connectivity

Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
vishal choudhary
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
NishaRohit6
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Unit 4 1 web technology uptu
Unit 4 1 web technology uptuUnit 4 1 web technology uptu
Unit 4 1 web technology uptu
Abhishek Kesharwani
 
Unit 4 web technology uptu
Unit 4 web technology uptuUnit 4 web technology uptu
Unit 4 web technology uptu
Abhishek Kesharwani
 
Chap4 4 2
Chap4 4 2Chap4 4 2
Chap4 4 2
Hemo Chella
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
IMC Institute
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
Auwal Amshi
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdf
Arumugam90
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Ayes Chinmay
 
Atul & shubha goswami jsp
Atul & shubha goswami jspAtul & shubha goswami jsp
Atul & shubha goswami jsp
Atul Giri
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
Kalpana T
 
WEB TECHNOLOGIES JSP
WEB TECHNOLOGIES  JSPWEB TECHNOLOGIES  JSP
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
Yoga Raja
 
Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course
JavaEE Trainers
 
4. jsp
4. jsp4. jsp
4. jsp
AnusAhmad
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
Aravindharamanan S
 

Similar to DataBase Connectivity (20)

Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Unit 4 1 web technology uptu
Unit 4 1 web technology uptuUnit 4 1 web technology uptu
Unit 4 1 web technology uptu
 
Unit 4 web technology uptu
Unit 4 web technology uptuUnit 4 web technology uptu
Unit 4 web technology uptu
 
Jsp tutorial
Jsp tutorialJsp tutorial
Jsp tutorial
 
JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
 
Chap4 4 2
Chap4 4 2Chap4 4 2
Chap4 4 2
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdf
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
 
J2EE jsp_01
J2EE jsp_01J2EE jsp_01
J2EE jsp_01
 
Atul & shubha goswami jsp
Atul & shubha goswami jspAtul & shubha goswami jsp
Atul & shubha goswami jsp
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
WEB TECHNOLOGIES JSP
WEB TECHNOLOGIES  JSPWEB TECHNOLOGIES  JSP
WEB TECHNOLOGIES JSP
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course
 
4. jsp
4. jsp4. jsp
4. jsp
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
 

Recently uploaded

JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
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
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
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
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
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
 
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
 
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
 
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
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 

Recently uploaded (20)

JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
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
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
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...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
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
 
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
 
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...
 
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
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 

DataBase Connectivity

  • 2.  Introduction JSP pages Markup Scriptlets Example  Accessing Database From JSP Page Steps to access database Example Description  References 2
  • 3. Java Server Pages (JSP) is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types. JSP pages are loaded in the server and operated from a structured special installed Java server packet called a Java EE Web Application, often packaged as a .war or .ear file archive. JSP allows Java code and certain pre- defined actions to be interleaved with static web markup content, with the resulting page being compiled and executed on the server to deliver an HTML or XML document. . 3
  • 4. 4 JSP allows Java code and certain pre-defined actions to be interleaved with static web markup content, with the resulting page being compiled and executed on the server to deliver an HTML or XML document. JSP syntax is a fluid mix of two basic content forms:  1. Scriptlet Elements  2. Markup
  • 5. Markup is typically standard HTML or XML. When the page is requested, the Java code is executed and its output is added with the surrounding markup to create the final page. Because Java is a compiled language, not a scripting language, JSP pages must be compiled to Java bytecode classes before they can be executed, but such compilation is needed only when a change to the source JSP file has occurred. 5
  • 6. Scriptlet elements are delimited blocks of Java code which may be intermixed with the markup. Java code is not required to be complete (self contained) within its scriptlet element block, but can straddle markup content providing the page as a whole is syntactically correct (for example, any Java if/for/while blocks opened in one scriptlet element must be correctly closed in a later element for the page to successfully compile). 6
  • 7. 7 Request JSP Engine and Web Server JSP file Component Client Response Request Request Response Response Fig: Data Passed b/w Client & Server
  • 8.  <%-- use the 'taglib' directive to make the JSTL 1.0 core tags available; use the uri  "http://java.sun.com/jsp/jstl/core" for JSTL 1.1 --%>  <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>   <%-- use the 'jsp:useBean' standard action to create the Date object; the object is set  as an attribute in page scope  --%>  <jsp:useBean id="date" class="java.util.Date" />   <html>  <head><title>First JSP</title></head>  <body>  <h2>Here is today's date</h2>  <c:out value="${date}" />  </body>  </html> 8
  • 9. 9 While accessing JSP database from JSP page, we should have some database package installed. Here we consider the connectivity from MYSQL database with JSP. Assumptions:  TOMCAT web server is installed.  MYSQL server is installed.  JDK is installed.
  • 10. Various steps are: 1. Create a database named “books”, statement is: MYSQL>CREATE DATABASE books ; 2. Create a table named “books_details”, statement is: MYSQL>CREATE TABLE books_details ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT , `book_name` VARCHAR( 100 ) NOT NULL , `author` VARCHAR( 100 ) NOT NULL , PRIMARY KEY ( `id` ) ) 10
  • 11. 11 The table is: ID Book Name Author 1. Java I/O Tim Ritchey 2. Java & XML, 2 Edition Brett McLaughlin 3. Java Swing, 2nd Edition Dave Wood, Marc Loy,
  • 12. 3. Copy the MYSQL-connector-java-3.1.14- bin.jar to the C:tomcat_directorycommonlib. Then set the Classpath. For that, we have to perform the following: Control Panel->System-> System Properties-> Environmental Variables and set Classpath. 12
  • 13. 13 4. After setting Classpath, restart the Tomcat Web Server using the startup.bat file at the command promt. Create a folder DBDemo using following line: C:tomcat_directoryjsp-examplesDBDemo and now write the JSP program which is used to connect the database.
  • 14. 14 <%@ page language="java" import="java.sql.*" %> <% Connection con=null; ResultSet rst=null; Statement stmt=null; String driver = "org.gjt.mm.mysql.Driver"; Class.forName(driver).newInstance(); Classes & interfaces object instantiation
  • 16. 16 if(request.getParameter("action") != null) { String book= request.getParameter("bookname"); String author=request.getParameter("author"); stmt.executeUpdate("insert into books_details(book_name, author) values('"+bookname+"','"+author+"')"); rst=stmt.executeQuery("select * from books_details"); %> Retrieve fields
  • 18. 1. JSP is a kind of scripting language in which we can embed JAVA code along with HTML elements. 2. Above code of JDBC and jsp shows how we can manipulate data in a relational database from JSP page. We need to use the java.sql package: DriverManager, Connection, Statement, and ResultSet. To create a Web application, we need JDBC to use more features such as prepared statements and connection pooling. 18
  • 19.  Figures- http://www.google.co.in  “Web Technology” by A.A.Puntambekar  http://www.wikipedia.org 19