Download - MDCFUG Is Java in Your Future?
![Page 2: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/2.jpg)
Agenda
• The Java Learning Curve
• Why This is a Good Thing
• J2EE Breakdown
• Sample Program
• Q & A
![Page 3: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/3.jpg)
My Background
• Consultant 2 1/2 years
• Certified CF Developer
• 4 years CF
• 1 year Java
• 6 years Oracle
![Page 4: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/4.jpg)
Java Language Barriers
• Non-Tag Based
• Lower Level Than CF (more code)
• Object Oriented
• Strongly Typed & Case Sensitive
• Large “Function Library”
• Powerful, Complex and Less Forgiving
![Page 5: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/5.jpg)
Power of Perception
• CF is Easy to Learn
• Ease of Entry Brings Less Qualified Programmers to the Language
• More Low Grade Programs are Written
• CF Language Gets a Bad Rap
![Page 6: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/6.jpg)
The Good Side of Barriers
• Less Competition
• Higher Rates
• Protected Reputation
![Page 7: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/7.jpg)
J2EE - Enterprise Java
• Server-side Web Development
• Standard Created by Sun
• Many Competing Application Servers
• App Servers Must Pass a Compatibility Test Suite
• Vendors Add Extensions & JSP Tag Libraries
![Page 8: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/8.jpg)
J2EE Technologies
• Lower Complexity– Java Server Pages (JSP)– Servlets
• Higher Complexity– JDBC (Database Connectivity)– Enterprise Java Beans (EJB)– Java Messaging Service (JMS)
![Page 9: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/9.jpg)
JSP Example
<%@ page info="Simple JSP Page example" %>
<%
String str = "8th";
%>
<html>
<head><title>Simple JSP Page</title></head>
<body bgcolor="#ffffff">
<h1>Welcome to the <%= str %> dimension</h1>
</body>
</html>
![Page 10: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/10.jpg)
Servlet Example
import java.io.*;
import servlet.*;
import servlet.http.*;
public class SimpleServlet extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
out.println(“<html><head><title>Simple Servlet Example</title></head>”);
out.println(“<body bgcolor="#ffffff">”);
String str = "8th";out.println(“<h1>Welcome to the ” + str + “ dimension</h1>”);
out.println(“</body></html>”);
}
}
![Page 11: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/11.jpg)
JDBC Example
Class.forName("oracle.jdbc.driver.OracleDriver");
String stUrl_= "jdbc:oracle:thin:@host:1521:sid";
Connection connection_ = DriverManager.getConnection(stUrl_, ”username",”password");
PreparedStatement statement_ = connection_.prepareStatement("SELECT fname, lname FROM EMPLOYEE");
ResultSet rs = statement_.executeQuery(); //execute query
while (rs.next()) {
String firstName = rs.getString(1);
String lastName = rs.getString(2);
strOut = strOut + firstName + " " + lastName + "<BR>";
}
rs.close();
statement_.close();
connection_.close();
![Page 12: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/12.jpg)
CF Comparison
<cfquery name="main_select" datasource="MYDS">
SELECT fname, lname FROM EMPLOYEE
</cfquery>
<cfoutput query="main_select">
#main_select.fname# #main_select.lname#
</cfoutput>
![Page 13: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/13.jpg)
JDBC Metadata
• getColumnCount - Returns the number of columns in this Result Set
• getColumnName - Get the designated column's name
• getColumnType - Retrieve the designated column's SQL type
• isAutoIncrement - Indicates whether the designated column is automatically numbered, thus read-only
![Page 14: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/14.jpg)
Model-View-Controller (MVC)
• Model = Data = JDBC
• View = Presentation = JSP
• Controller = Framework = Servlet
![Page 15: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/15.jpg)
MVC Flow
1) Client submits a page request
2) Servlet interprets request
3) Servlet retrieves necessary info from JDBC
4) Servlet hands off request and details to JSP for formatting and presentation
Client
Servlet
JSP
JDBC
![Page 16: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/16.jpg)
Complete MVC Example
• DimensionApp.java (Servlet)
• DimensionVO.java (JDCB Class)
• Display.jsp (JSP)
![Page 17: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/17.jpg)
DimensionApp.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import DimensionVO;
public class DimensionApp extends HttpServlet {
public void service (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
DimensionVO dvo = new DimensionVO();
String mydim = dvo.getDimension();
req.setAttribute("dimension", mydim);
RequestDispatcher rd;
rd = getServletContext().getRequestDispatcher("/jsp/Display.jsp");
rd.forward(req, res);
}
}
![Page 18: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/18.jpg)
DimensionVO.javaimport java.sql.*;
import java.util.*;
import java.io.*;
public class DimensionVO {
String strOut;
String stUrl_= "jdbc:odbc:mdcfug";
private Connection connection_ = null;
private PreparedStatement statement_ = null;
private ResultSet rs;
public String getDimension ()
throws IOException {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection_ = DriverManager.getConnection(stUrl_, "Admin","");
statement_ = connection_.prepareStatement("SELECT dimension FROM DIMENSIONS");
rs = statement_.executeQuery(); //execute query
String mydim = rs.getString(1);
strOut = mydim;
rs.close();
statement_.close();
connection_.close();
}
catch (ClassNotFoundException e) {// Shouldn't happen - it comes with the JRE}
catch (SQLException e) {System.err.println("Unable to connect to the DB " + e);}
return strOut;
}
}
![Page 19: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/19.jpg)
Display.jsp
<%@ page info="MVC Example" %>
<%String str = (String)request.getAttribute("dimension");%>
<html>
<head><title>MVC Example</title></head>
<body bgcolor="#ffffff">
<table>
<tr>
<td width=150> </td>
<td width=250 align=right> <h1>Welcome to the <%= str %> dimension</h1> </td>
</tr>
</table>
</body>
</html>
![Page 20: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/20.jpg)
Java Resources
• Java’s Home @ Sun– http://java.sun.com
• Java Portals– http://www.theserverside.com
– http://www.jguru.com/• Sun’s JDBC Tutorial
– http://developer.java.sun.com/developer/onlineTraining/Database/JDBC20Intro/
![Page 21: MDCFUG Is Java in Your Future?](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56814937550346895db67a61/html5/thumbnails/21.jpg)
Java Bookshelf
• The Java Language– Java in a Nutshell - Flanagan
• Servlets/JSP– Java Servlet Programming - Hunter
– Web Development With JavaServer Pages - Fields/Kolb
– Core Servlets and JavaServer Pages - Hall
• J2EE Application Architecture– Core J2EE Patterns - Alur