1 / 21

MDCFUG Is Java in Your Future?

MDCFUG Is Java in Your Future?. Tyler Williams Principal Consultant @ dataTerrace twilliams@dataterrace.com. Agenda. The Java Learning Curve Why This is a Good Thing J2EE Breakdown Sample Program Q & A. My Background. Consultant 2 1/2 years Certified CF Developer 4 years CF

keitha
Download Presentation

MDCFUG Is Java in Your Future?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MDCFUGIs 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 <%@ 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>

  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(“<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>”); } }

  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 + "<BR>"; } rs.close(); statement_.close(); connection_.close();

  12. 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>

  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 Client 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 Servlet JDBC JSP

  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 <%@ 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> &nbsp; </td> <td width=250 align=right> <h1>Welcome to the <%= str %> dimension</h1> </td> </tr> </table> </body> </html>

  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

More Related