Download presentation
Presentation is loading. Please wait.
Published byAshley Brooks Modified over 9 years ago
1
MDCFUG Is Java in Your Future? Tyler Williams Principal Consultant @ dataTerrace twilliams@dataterrace.com
2
Agenda The Java Learning Curve Why This is a Good Thing J2EE Breakdown Sample Program Q & A
3
My Background Consultant 2 1/2 years Certified CF Developer 4 years CF 1 year Java 6 years Oracle
4
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
5
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
6
The Good Side of Barriers Less Competition Higher Rates Protected Reputation
7
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
8
J2EE Technologies Lower Complexity –Java Server Pages (JSP) –Servlets Higher Complexity –JDBC (Database Connectivity) –Enterprise Java Beans (EJB) –Java Messaging Service (JMS)
9
JSP Example <% String str = "8th"; %> Simple JSP Page Welcome to the dimension
10
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(“ Simple Servlet Example ”); out.println(“ ”); String str = "8th"; out.println(“ Welcome to the ” + str + “ dimension ”); out.println(“ ”); }
11
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 + " "; } rs.close(); statement_.close(); connection_.close();
12
CF Comparison SELECT fname, lname FROM EMPLOYEE #main_select.fname# #main_select.lname#
13
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
14
Model-View-Controller (MVC) Model = Data = JDBC View = Presentation = JSP Controller = Framework = Servlet
15
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
16
Complete MVC Example DimensionApp.java (Servlet) DimensionVO.java (JDCB Class) Display.jsp (JSP)
17
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); }
18
DimensionVO.java import 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; }
19
Display.jsp MVC Example Welcome to the dimension
20
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/
21
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
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.