J2EE (Enterprise Programing)

Slides:



Advertisements
Similar presentations
Apache Tomcat as a container for Servlets and JSP
Advertisements

Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
Servlets Stoney Jackson
Object Oriented Programming Java Java’s JDBC Allows access to any ANSI SQL-2 DBMS Does its work in terms of SQL The JDBC has classes that represent:
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
2/16/2004 Dynamic Content February 16, /16/2004 Assignments Due – Message of the Day Part 1 Due – Reading and Warmup Work on Message of the Day.
1 Dickson K.W. Chiu PhD, SMIEEE Reference: Sun J2EE 1.4 Tutorial CSIT600b: XML Programming XML Programming Guide: Getting Started.
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Java MS Access database connectivity Follow these steps: 1)Go to the start->Control Panel->Administrative Tools- > data sources. 2)Click Add button and.
1 Databases & Web-based Applications JDBC & Java Servlets A. Benabdelkader ©UvA, 2002/2003.
Servlets Pranav Maydeo. What is a Servlet ? Servlets are modules of Java code that run in a server application to answer client requests. Servlets are.
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
CSC 2720 Building Web Applications
Java Servlets and Java Server Pages Carol Wolf Computer Science.
DataBases and SQL INFSY 547 Spring Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Servlet Lifecycle Lec 28. Servlet Life Cycle  Initialize  Service  Destroy Time.
MDCFUG Is Java in Your Future? Tyler Williams Principal dataTerrace
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
Java Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface Servlet and the Servlet Life Cycle HttpServlet Class.
Java Servlets & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Why server side programming ?. What is java servlet ?
JDBC – Java DataBase Connectivity. JDBC API Overview JDBC is Java API that allows the Java programmers to access database management system from Java.
JSP Presented by K.Venkata Ratnam HOD MCA (Dept) Newton’s Institute of Engineering.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
S ERVLETS Hits Counter 21-Nov-15. S ERVLETS - H ITS C OUNTER Many times you would be interested in knowing total number of hits on a particular page of.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
 2002 Prentice Hall. All rights reserved. 9.8 Multi-Tier Applications: Using JDBC from a Servlet Three-tier distributed applications –User interface –Business.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Introduction to Servlets. Introduction Servlet is a language to develop the server side applications, and it is also server side component. It can develop.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Configuration Web Server Tomcat - Install JDK Install Tom cat Configure Tom cat for running Servlet C:\Program Files\Apache Software Foundation\Tomcat.
Java and the Web CSE 3330 Southern Methodist University.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
ClaRA web services V. Gyurjyan Clas12 Software Meeting
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
April 20023CSG11 Electronic Commerce Java (2) John Wordsworth Department of Computer Science The University of Reading Room 129,
Java Database Connectivity JDBC. Open Database Connectivity developed by Microsoft to provide interaction with databases using SQL. Use the JDBC-ODBC.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Introduction to Servlets
PERTEMUAN 7.
PERTEMUAN 3.
PERTEMUAN 2.
Java Servlets By: Tejashri Udavant..
PERTEMUAN 5.
DATABASE IN JAVA.
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
SERVLETS AND JDBC.
Jagdish Gangolly State University of New York at Albany
JAVA DATABaSE CONNECTIVITY
Servlets.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Java Servlets Servlet Overview Servlets and HTML Forms Servlet Basics
Introduction to Java Servlets
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Introduction to Servlet
Basic servlet structure
COSC 2206 Internet Tools Java Servlets with JDBC and MySQL
Presentation transcript:

J2EE (Enterprise Programing) Koneksi Database

KONEKSI DATABASE Database DSN Coding java Convert ke class Deploy tools Cek di Browser

Membuat Database Buat database “dbmahasiswami” yang di dalamnya terdapat 1 tabel : tbMahasiswa FIELD TYPE KETERANGAN Nim Varchar (8) Primary key Nama Varchar (20) Alamat Varchar (30)

Membuat DSN Buka Control Panel >> Administrative Tools >> Data Sources (ODBC) Pada tab User DSN Pilih Add >> MySQL ODBC 5.1 Driver Data Source Name = mahasiswami Server = localhost User = root

Coding Koneksi (1) import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; public class koneksi extends HttpServlet{ PrintWriter out=null; Connection con=null; ResultSet rs=null; public void service (HttpServletRequest rq, HttpServletResponse rs) throws ServletException, IOException{ out=rs.getWriter();

Coding Koneksi (2) try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:mahasiswami","root",""); out.println("Koneksi Berhasil"); } catch(Exception e){ out.println (e.toString()); out.println("Koneksi Gagal");

Ubah coding koneksi ke file class Jalankan di “deploytool” Cek koneksi di browser anda

Menampilkan Isi Database Coding java Convert ke class Deploy tools Cek di Browser

Mengisi Database Isi tbMahasiswa dengan data sebagai berikut : NIM Nama Alamat 101001 John Jakarta 101002 Peter Sukabumi 101003 Clara Cirebon 101004 Veronica Jogja 101005 Michael Bandung

Coding (1) import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; public class lihatdatabase extends HttpServlet{ static int i; Connection con; PrintWriter out; ResultSet rs; public void init(){ i = 0; con=null; out=null; rs=null; } //close void init()

Coding (2) public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ i++; out=response.getWriter(); out.println("<B>You are user no. " + i +" to visit this site.</B><BR><BR>"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:mahasiswa","root",""); PreparedStatement pstmt=null; String query=null; query= "select * from tb_mahasiswa"; pstmt=con.prepareStatement(query); rs=pstmt.executeQuery(); out.println("<B><center>Data Mahasiswa</center></B>"); ResultSetMetaData rsmd= rs.getMetaData(); int colcount=rsmd.getColumnCount();

Coding (3) out.println("<TABLE ALIGN = CENTER BORDER=1 CELLPADDING=2>"); out.println("<TR>"); out.println("<TH>NIM</TH>"); out.println("<TH>Nama</TH>"); out.println("<TH>Alamat</TH>"); out.println("</TR>"); while(rs.next()){ out.println("<TD>" + rs.getString("nim") + "</TD>"); out.println("<TD>" + rs.getString("nama") + "</TD>"); out.println("<TD>" + rs.getString("alamat") + "</TD>"); } // close while out.println("</TABLE>"); out.println("</BODY>"); } // close try

Coding (4) catch(Exception e){ out.println(e.toString()); } // close catch } // close void doGet public void destroy(){ try{ i = 0; con.close(); out.close(); rs.close(); } // close try catch (SQLException se){ out.println(se.toString()); } //close void destroy() } //close class

Simpan coding di lihatdatabasemi.java Ubah file java ke file class Deploytools Context Root : praktikumtigami Aliases : lihatdatabasemi

Cek di Browser

TERIMA KASIH