SlideShare a Scribd company logo
7
Most read
10
Most read
11
Most read
Java Servlets
Java Server Pages
(JSP)
Yi Lin
Overview of History
CGI
(in C)
Template
(ASP, PHP)
Servlet
CGI
(java, C++)
JSP
Speed, Security
complexity
HelloWorld
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello CS764!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello CS764!</h1>");
out.println("</body>");
out.println("</html>");
out.close();
}
}
<html><head></head>
<body>
<a href="../servlet/HelloWorld">
<h1>Execute HelloWorld Servlet</h1>
</a>
</body>
</html>
<html>
<head>
<title>Hello CS764!</title></head>
<body>
<h1>Hello CS764!</h1>
</body>
</html>
Client - Server - DB
Client
(browser)
Web server
(Apache, JWS)
Database
server (DB2)
Through
internet
Return html file
(Response)
Trigger Servlet, JSP
(Request)
JDBC,
intranet
Request
data
Return
data
Life Cycle of Servlet
init(ServletConfig);
service(ServletRequest,
ServletResponse);
destroy();
servlet
GenericServlet HttpServlet
doGet(HttpServletRequest,
HttpServletResponse);
doPost(HttpServletRequest,
HttpServletResponse);
…….
Interaction with Client
• HttpServletRequest
– String getParameter(String)
– Enumeration getParameters(String[])
• HttpServletResponse
– Writer getWriter()
– ServletOutputStream getOutputStream()
• Handling GET and POST Requests
Assignment 2:
Get Stock Price
<html><head></head>
<body>
<form action="../servlet/Ass2Servlet" method=POST>
<h2>Stock Symbol name:
<input type=text name="stockSymbol"></h2><br>
<input type="submit" value = "get price">
</form>
</body></html>
Client Side
Ass2.html
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Ass2Servlet extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse res)
throws IOException, ServletException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String stockSymb = request.getParameter("stockSymbol");
StockGrabber sg = new StockGrabber();
sg.setStockSymbol(stockSymb); // Set the stock symbol as “input”
String stockPrice = sg.getPrice();// Get the price of stock
System.out.println("After StockGrabber.getPrice --"+stockPrice);// Debug
out.println("<html><head></head><body><br><br>");
out.println(stockSymb + " -- " + stockPrice);
out.println("<hr>");
out.println("<form action="../servlet/Ass2Servlet" method=POST>");
out.println("<h3>Stock Symbol name: <input type=text name="stockSymbol"></h3>");
out.println("<input type=submit value="get price">");
out.println("</form>");
out.println("</body></html>");
}
}
Ass2Servlet
Java Server Pages (JSP)
Client’s
Computer
Server
1.Browser requests HTML
7. Server sends HTML
back to browser
servlet
servlet
class 5.The servlet
runs and
generates
HTML
Java Engine
6. Java Engine sends HTML to server
2. Server sends requests to Java Engine
3. If needed, the Java Engine
reads the .jsp file
4. The JSP is turned into a
servlet, compiled, and loaded
Bean
A First JSP
<html>
<head></head>
<body>
<p>Enter two numbers and click the
‘calculate’ button.</p>
<form action=“calculator.jsp” method=“get”>
<input type=text name=value1><br>
<input type=text name=value2 ><br>
<input type=submit name=calculate value=calculate>
</form>
</body>
</html>
Calculator.html
<html>
<head><title>A simple calculator: results</title></head>
<body>
<%-- A simpler example 1+1=2 --%>
1+1 = <%= 1+1 %>
<%-- A simple calculator --%>
<h2>The sum of your two numbers is:</h2>
<%= Integer.parseInt(request.getParameter("value1")) +
Integer.parseInt(request.getParameter("value2")) %>
</body>
</html>
Calculator.jsp
JSP Tags
• Comments <%-- …...text…... --%>
• Declaration <%! int i; %>
<%! int numOfStudents(arg1,..) {} %>
• Expression <%= 1+1 %>
• Scriptlets <% … java code … %>
• include file <%@ include file=“*.jsp” %>
• …...
Using Java Bean
1. <jsp:useBean id=“bean1” class=“Bean1”/>
2. <jsp:useBean id=“bean1” class=“Bean1” name=“serBean” type=“SerBean1”/>
Declaration
Getting property
1. <jsp:getProperty name=“bean1” property=“color”/>
2. <%=bean1.getColor() %>
Setting property
1. <jsp:setProperty name=“bean1” property=“color” value=“red”/>
2. <jsp:setProperty name=“bean1” property=“color”/>
3. <jsp:setProperty name=“bean1” property=“color” param=“bgColor”/>
4. <jsp:setProperty name=“bean1” property=“*”/>
Assg2
example
<html>
<head></head>
<body>
<center>
<table border = 0>
<form action=ass2.jsp method = POST>
<tr><td><font color=blue>choose a stock market:</font></td>
<td><select name="stockMarket">
<option value="Waterhouse">Waterhouse</option>
<option value="Yahoo">Yahoo</option>
<option value="ChicagoStockex">Chicago Stockex</option>
<option value="Reuters">Reuters</option>
</select></td>
</tr>
<tr><td><font color = blue>input a stock symbol:</font></td>
<td><input type="edit" name="stockSymbol" size=15></td>
</tr>
<tr><td></td><td><input type="submit" value = "get price"></td></tr>
</table>
</form></center>
</body></html>
Client side
Ass2.html
Server side
ass2.jsp
<html><head>
<jsp:useBean id="ass2" scope="session" class="ass2.StockGrabber" />
<jsp:setProperty name="ass2" property="*" />
</head>
<body><h2><%
ass2.processInput();
ass2.getPrice();
%>
<center><table border=5>
<tr><td># of data</td> <td>Stock Market</td> <td>Stock Symbol</td> <td>Stock Price </td>
</tr><%
String[] stockMarkets = ass2.getStockMarkets();
String[] symbols = ass2.getSymbols();
String[] prices = ass2.getPrices();
for(int i=0; i<prices.length; i++){
%>
<tr><td> <%= i+1 %> </td>
<td> <%= stockMarkets[i] %> </td>
<td> <%= symbols[i] %> </td>
<td><font color=red><%= prices[i] %></font></td>
</tr><%
}
%>
</table>
</center>
</h2>
<hr><%@include file="ass2.html" %></html>
<jsp:setProperty name=“ass2” property=“stockSymbol”/>
<jsp:setProperty name=“ass2” property=“stockMarket”/>
presentation on java server pages vs servlet.ppt
Without using JDBC
Public class StockGrabber {
...
public void processInput(){
if(stockMarket.compareTo("Waterhouse")==0){
setPrePriceString("<!--Last-->");
setPostPriceString("</FONT>");
setUrlPrefix("http://research.tdwaterhouse.com/
waterhouse/quote.asp?ticker=");
}
else if(stockMarket.compareTo("Yahoo")==0){
setPrePriceString("<td nowrap><b>");
setPostPriceString("</b></td>");
setUrlPrefix("http://finance.yahoo.com/q?s=");
}
...
else if(...){}
...
else{...}
}
...
}
Using JDBC --> Database
import java.sql.*;
Public class StockGrabber {
...
public void processInput(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sourceURL="jdbc:odbc:stockInfo";
Connection databaseConnection=DriverManager.getConnection(sourceURL);
Statement statement=databaseConnection.createStatement();
ResultSet info =statement.executeQuery(
"select tPrePriceStr, tPostPriceStr, tUrlPrefix
from stockMarketData
where tStockMarket = stockMarket”);
while(inf.next())
{
prePriceString = info.getString(”tPrePriceStr");
postPriceString = info.getString(“tPostPriceStr”);
urlPrefix = info.getString(“tUrlPrefix”);
}
}
catch(SQLException e){ ... }
...
}
}

More Related Content

Similar to presentation on java server pages vs servlet.ppt (20)

PDF
HTTP, JSP, and AJAX.pdf
Arumugam90
 
PDF
JavaServer Pages
Abdalla Mahmoud
 
PPT
Jsp intro
husnara mohammad
 
PDF
servlets
Arjun Shanka
 
PPT
Java servlets
lopjuan
 
PPTX
BITM3730Week12.pptx
MattMarino13
 
PDF
Dynamic content generation
Eleonora Ciceri
 
PPT
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
sindhu991994
 
PPT
What is Advance Java J2EE
javaease
 
PDF
10 jsp-scripting-elements
Phạm Thu Thủy
 
PPTX
Java web application development
RitikRathaur
 
PPTX
JAVA SERVER PAGES
Kalpana T
 
PPTX
servlets sessions and cookies, jdbc connectivity
snehalatha790700
 
TXT
Jsp Notes
Rajiv Gupta
 
PDF
JSP Components and Directives.pdf
Arumugam90
 
PPTX
JavaServer Pages
profbnk
 
PPTX
Core web application development
Bahaa Farouk
 
PDF
Java Servlets.pdf
Arumugam90
 
PDF
Java Web Programming [2/9] : Servlet Basic
IMC Institute
 
HTTP, JSP, and AJAX.pdf
Arumugam90
 
JavaServer Pages
Abdalla Mahmoud
 
Jsp intro
husnara mohammad
 
servlets
Arjun Shanka
 
Java servlets
lopjuan
 
BITM3730Week12.pptx
MattMarino13
 
Dynamic content generation
Eleonora Ciceri
 
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
sindhu991994
 
What is Advance Java J2EE
javaease
 
10 jsp-scripting-elements
Phạm Thu Thủy
 
Java web application development
RitikRathaur
 
JAVA SERVER PAGES
Kalpana T
 
servlets sessions and cookies, jdbc connectivity
snehalatha790700
 
Jsp Notes
Rajiv Gupta
 
JSP Components and Directives.pdf
Arumugam90
 
JavaServer Pages
profbnk
 
Core web application development
Bahaa Farouk
 
Java Servlets.pdf
Arumugam90
 
Java Web Programming [2/9] : Servlet Basic
IMC Institute
 

More from ansariparveen06 (20)

PPT
Preprocessing of data mining process.ppt
ansariparveen06
 
PPT
8. Ozone and Environmental issue and solution.ppt
ansariparveen06
 
PPTX
ALP intro assembly language programing.pptx
ansariparveen06
 
PPT
cpphtp9_Exception handling in c++ .ppt
ansariparveen06
 
PPT
introduction to javascript concepts .ppt
ansariparveen06
 
PPT
java multi threading and synchronisation.ppt
ansariparveen06
 
PPTX
Environmental studies part2 bscit sem2.pptx
ansariparveen06
 
PPTX
ENVIRONMENTAL STUDIES FYBSCIT SEM 2.pptx
ansariparveen06
 
PPT
exception-handling-in-java programming.ppt
ansariparveen06
 
PPTX
brief introduction to core java programming.pptx
ansariparveen06
 
PPTX
Module1 evs Environmental Pollution.pptx
ansariparveen06
 
PPTX
Internet_Banking e commerce in banking.pptx
ansariparveen06
 
PPTX
UNIT1 Decision Support System in BI.pptx
ansariparveen06
 
PPT
logic gate based on discrete mathematics.ppt
ansariparveen06
 
PPTX
Overview on how to Disciplining in life .pptx
ansariparveen06
 
PPT
Introduction to Java Servlets and JSP (1).ppt
ansariparveen06
 
PPTX
enterprise java - introduction to servlet.pptx
ansariparveen06
 
PPTX
Introduction to Operating - Systems.pptx
ansariparveen06
 
PDF
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
ansariparveen06
 
PDF
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
ansariparveen06
 
Preprocessing of data mining process.ppt
ansariparveen06
 
8. Ozone and Environmental issue and solution.ppt
ansariparveen06
 
ALP intro assembly language programing.pptx
ansariparveen06
 
cpphtp9_Exception handling in c++ .ppt
ansariparveen06
 
introduction to javascript concepts .ppt
ansariparveen06
 
java multi threading and synchronisation.ppt
ansariparveen06
 
Environmental studies part2 bscit sem2.pptx
ansariparveen06
 
ENVIRONMENTAL STUDIES FYBSCIT SEM 2.pptx
ansariparveen06
 
exception-handling-in-java programming.ppt
ansariparveen06
 
brief introduction to core java programming.pptx
ansariparveen06
 
Module1 evs Environmental Pollution.pptx
ansariparveen06
 
Internet_Banking e commerce in banking.pptx
ansariparveen06
 
UNIT1 Decision Support System in BI.pptx
ansariparveen06
 
logic gate based on discrete mathematics.ppt
ansariparveen06
 
Overview on how to Disciplining in life .pptx
ansariparveen06
 
Introduction to Java Servlets and JSP (1).ppt
ansariparveen06
 
enterprise java - introduction to servlet.pptx
ansariparveen06
 
Introduction to Operating - Systems.pptx
ansariparveen06
 
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
ansariparveen06
 
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
ansariparveen06
 
Ad

Recently uploaded (20)

PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Introduction presentation of the patentbutler tool
MIPLM
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Horarios de distribución de agua en julio
pegazohn1978
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
Ad

presentation on java server pages vs servlet.ppt

  • 1. Java Servlets Java Server Pages (JSP) Yi Lin
  • 2. Overview of History CGI (in C) Template (ASP, PHP) Servlet CGI (java, C++) JSP Speed, Security complexity
  • 3. HelloWorld import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<body>"); out.println("<head>"); out.println("<title>Hello CS764!</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Hello CS764!</h1>"); out.println("</body>"); out.println("</html>"); out.close(); } }
  • 4. <html><head></head> <body> <a href="../servlet/HelloWorld"> <h1>Execute HelloWorld Servlet</h1> </a> </body> </html> <html> <head> <title>Hello CS764!</title></head> <body> <h1>Hello CS764!</h1> </body> </html>
  • 5. Client - Server - DB Client (browser) Web server (Apache, JWS) Database server (DB2) Through internet Return html file (Response) Trigger Servlet, JSP (Request) JDBC, intranet Request data Return data
  • 6. Life Cycle of Servlet init(ServletConfig); service(ServletRequest, ServletResponse); destroy(); servlet GenericServlet HttpServlet doGet(HttpServletRequest, HttpServletResponse); doPost(HttpServletRequest, HttpServletResponse); …….
  • 7. Interaction with Client • HttpServletRequest – String getParameter(String) – Enumeration getParameters(String[]) • HttpServletResponse – Writer getWriter() – ServletOutputStream getOutputStream() • Handling GET and POST Requests
  • 8. Assignment 2: Get Stock Price <html><head></head> <body> <form action="../servlet/Ass2Servlet" method=POST> <h2>Stock Symbol name: <input type=text name="stockSymbol"></h2><br> <input type="submit" value = "get price"> </form> </body></html> Client Side Ass2.html
  • 9. import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class Ass2Servlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String stockSymb = request.getParameter("stockSymbol"); StockGrabber sg = new StockGrabber(); sg.setStockSymbol(stockSymb); // Set the stock symbol as “input” String stockPrice = sg.getPrice();// Get the price of stock System.out.println("After StockGrabber.getPrice --"+stockPrice);// Debug out.println("<html><head></head><body><br><br>"); out.println(stockSymb + " -- " + stockPrice); out.println("<hr>"); out.println("<form action="../servlet/Ass2Servlet" method=POST>"); out.println("<h3>Stock Symbol name: <input type=text name="stockSymbol"></h3>"); out.println("<input type=submit value="get price">"); out.println("</form>"); out.println("</body></html>"); } } Ass2Servlet
  • 10. Java Server Pages (JSP) Client’s Computer Server 1.Browser requests HTML 7. Server sends HTML back to browser servlet servlet class 5.The servlet runs and generates HTML Java Engine 6. Java Engine sends HTML to server 2. Server sends requests to Java Engine 3. If needed, the Java Engine reads the .jsp file 4. The JSP is turned into a servlet, compiled, and loaded Bean
  • 11. A First JSP <html> <head></head> <body> <p>Enter two numbers and click the ‘calculate’ button.</p> <form action=“calculator.jsp” method=“get”> <input type=text name=value1><br> <input type=text name=value2 ><br> <input type=submit name=calculate value=calculate> </form> </body> </html> Calculator.html
  • 12. <html> <head><title>A simple calculator: results</title></head> <body> <%-- A simpler example 1+1=2 --%> 1+1 = <%= 1+1 %> <%-- A simple calculator --%> <h2>The sum of your two numbers is:</h2> <%= Integer.parseInt(request.getParameter("value1")) + Integer.parseInt(request.getParameter("value2")) %> </body> </html> Calculator.jsp
  • 13. JSP Tags • Comments <%-- …...text…... --%> • Declaration <%! int i; %> <%! int numOfStudents(arg1,..) {} %> • Expression <%= 1+1 %> • Scriptlets <% … java code … %> • include file <%@ include file=“*.jsp” %> • …...
  • 14. Using Java Bean 1. <jsp:useBean id=“bean1” class=“Bean1”/> 2. <jsp:useBean id=“bean1” class=“Bean1” name=“serBean” type=“SerBean1”/> Declaration Getting property 1. <jsp:getProperty name=“bean1” property=“color”/> 2. <%=bean1.getColor() %> Setting property 1. <jsp:setProperty name=“bean1” property=“color” value=“red”/> 2. <jsp:setProperty name=“bean1” property=“color”/> 3. <jsp:setProperty name=“bean1” property=“color” param=“bgColor”/> 4. <jsp:setProperty name=“bean1” property=“*”/>
  • 15. Assg2 example <html> <head></head> <body> <center> <table border = 0> <form action=ass2.jsp method = POST> <tr><td><font color=blue>choose a stock market:</font></td> <td><select name="stockMarket"> <option value="Waterhouse">Waterhouse</option> <option value="Yahoo">Yahoo</option> <option value="ChicagoStockex">Chicago Stockex</option> <option value="Reuters">Reuters</option> </select></td> </tr> <tr><td><font color = blue>input a stock symbol:</font></td> <td><input type="edit" name="stockSymbol" size=15></td> </tr> <tr><td></td><td><input type="submit" value = "get price"></td></tr> </table> </form></center> </body></html> Client side Ass2.html
  • 16. Server side ass2.jsp <html><head> <jsp:useBean id="ass2" scope="session" class="ass2.StockGrabber" /> <jsp:setProperty name="ass2" property="*" /> </head> <body><h2><% ass2.processInput(); ass2.getPrice(); %> <center><table border=5> <tr><td># of data</td> <td>Stock Market</td> <td>Stock Symbol</td> <td>Stock Price </td> </tr><% String[] stockMarkets = ass2.getStockMarkets(); String[] symbols = ass2.getSymbols(); String[] prices = ass2.getPrices(); for(int i=0; i<prices.length; i++){ %> <tr><td> <%= i+1 %> </td> <td> <%= stockMarkets[i] %> </td> <td> <%= symbols[i] %> </td> <td><font color=red><%= prices[i] %></font></td> </tr><% } %> </table> </center> </h2> <hr><%@include file="ass2.html" %></html> <jsp:setProperty name=“ass2” property=“stockSymbol”/> <jsp:setProperty name=“ass2” property=“stockMarket”/>
  • 18. Without using JDBC Public class StockGrabber { ... public void processInput(){ if(stockMarket.compareTo("Waterhouse")==0){ setPrePriceString("<!--Last-->"); setPostPriceString("</FONT>"); setUrlPrefix("http://research.tdwaterhouse.com/ waterhouse/quote.asp?ticker="); } else if(stockMarket.compareTo("Yahoo")==0){ setPrePriceString("<td nowrap><b>"); setPostPriceString("</b></td>"); setUrlPrefix("http://finance.yahoo.com/q?s="); } ... else if(...){} ... else{...} } ... }
  • 19. Using JDBC --> Database import java.sql.*; Public class StockGrabber { ... public void processInput(){ try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String sourceURL="jdbc:odbc:stockInfo"; Connection databaseConnection=DriverManager.getConnection(sourceURL); Statement statement=databaseConnection.createStatement(); ResultSet info =statement.executeQuery( "select tPrePriceStr, tPostPriceStr, tUrlPrefix from stockMarketData where tStockMarket = stockMarket”); while(inf.next()) { prePriceString = info.getString(”tPrePriceStr"); postPriceString = info.getString(“tPostPriceStr”); urlPrefix = info.getString(“tUrlPrefix”); } } catch(SQLException e){ ... } ... } }