WEB SERVICES EXAMPLE 2

Similar documents
CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

1. PhP Project. Create a new PhP Project as shown below and click next

SQream Connector JDBC SQream Technologies Version 2.9.3

Accessing databases in Java using JDBC

Databases and SQL Lab EECS 448

Assignment -3 Source Code. Student.java

Java application using JDBC to connect to a database.

Tiers (or layers) Separation of concerns

DB I. 1 Dr. Ahmed ElShafee, Java course

Overview of Web Services API

Java Database Connectivity

DATABASE DESIGN I - 1DL300

Author - Ashfaque Ahmed

EJB - ACCESS DATABASE

CreateServlet.java

Working with Databases and Java

Java Database Connectivity (JDBC) 25.1 What is JDBC?

Databases 2012 Embedded SQL

Database Application Development

Complimentary material for the book Software Engineering in the Agile World

Server-side Web Programming

Database Access with JDBC. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

OpenScape Voice V8 Application Developers Manual. Programming Guide A31003-H8080-R

Servlet 5.1 JDBC 5.2 JDBC

Oracle Exam 1z0-809 Java SE 8 Programmer II Version: 6.0 [ Total Questions: 128 ]

Distributed Systems Project 5 Assigned: Friday, April 6, 2012 Due: Friday, April 20, 11:59:59 PM

Databases CSCI 201 Principles of Software Development

Lab # 9. Java to Database Connection

e-pg Pathshala Subject: Computer Science Paper: Web Technology Module: JDBC INTRODUCTION Module No: CS/WT/26 Quadrant 2 e-text

ERwin and JDBC. Mar. 6, 2007 Myoung Ho Kim

Running SQL in Java and PHP

Enterprise Java Unit 1- Chapter 6 Prof. Sujata Rizal

JDBC Guide. RDM Server 8.2

Java Database Connectivity

Running SQL in Java and PHP

Server-side Web Programming

COP4540 TUTORIAL PROFESSOR: DR SHU-CHING CHEN TA: H S IN-YU HA

13 Creation and Manipulation of Tables and Databases

Enterprise Systems. Lecture 02: JDBC. Behzad BORDBAR

DataBase Lab JAVA-DATABASE CONNECTION. Eng. Haneen El-masry

Université Antonine - Baabda

Chapter 10 Java and SQL. Wang Yang

Voyager Database Developer s Guide Version 1.0 for Voyager 8.0

CSCI/CMPE Object-Oriented Programming in Java JDBC. Dongchul Kim. Department of Computer Science University of Texas Rio Grande Valley

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Science and Engineering

You write standard JDBC API application and plug in the appropriate JDBC driver for the database the you want to use. Java applet, app or servlets

2018/2/5 话费券企业客户接入文档 语雀

Getting Started with the Bullhorn SOAP API and Java

SQL in a Server Environment

Database Programming Overview. COSC 304 Introduction to Database Systems. Database Programming. JDBC Interfaces. JDBC Overview

JDBC Java Database Connectivity is a Java feature that lets you connect

SPRING DECLARATIVE TRANSACTION MANAGEMENT

JDBC [Java DataBase Connectivity]

Database Application Development

Introduction to Java Development with IDS

Object Oriented Programming

EXAMINATION FOR THE DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 2

Programming a Bank Database. We ll store the information in two tables: INTEGER DECIMAL(10, 2)

Pieter van den Hombergh. March 25, 2018

SQL: Programming. Announcements (September 25) Motivation. CPS 116 Introduction to Database Systems. Pros and cons of SQL.

Prof. Edwar Saliba Júnior

COMP 430 Intro. to Database Systems. SQL from application code

MANTHLY TEST SEPTEMBER 2017 QUESTION BANK CLASS: XII SUBJECT: INFORMATICS PRACTICES (065)

Databases and JDBC. by Vlad Costel Ungureanu for Learn Stuff

Visit for more.

Injection Of Datasource

UNIT-3 Java Database Client/Server

while (rs.next()) { String[] temp_array = {"","",""}; int prodid = rs.getint(1); temp_array[0] = ""+prodid;

Unit 3 - Java Data Base Connectivity

SQL CSCI 201 Principles of Software Development

Prof. Edwar Saliba Júnior

JDBC Drivers Type. JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server.

Introduction to Databases

JDBC, Transactions. Niklas Fors JDBC 1 / 38

Connessione.java. package model.entity; import java.sql.connection; public class Connessione { public Connection objconn;

Chapter 9 SQL in a server environment

JDBC. Oracle ODBC SP API SP API. SQL server C function calls. SQL server ODBC SP API. Oracle DSN Oracle ODBC Oracle

This example uses a Web Service that is available at xmethods.net, namely RestFulServices's Currency Convertor.

UNIT III - JDBC Two Marks

SQL: Programming Midterm in class next Thursday (October 5)

Backend. (Very) Simple server examples

Building a XML gateway architecture for JDBC using JAX-RPC web services

Java and XML. XML documents consist of Elements. Each element will contains other elements and will have Attributes. For example:

Installing MySQL. Hibernate: Setup, Use, and Mapping file. Setup Hibernate in IDE. Starting WAMP server. phpmyadmin web console

PESIT Bangalore South Campus

Inserting users from SQL data to Active Directory

Discuss setting up JDBC connectivity. Demonstrate a JDBC program Discuss and demonstrate methods associated with JDBC connectivity

Project Documentation

VanillaCore Walkthrough Part 1. Introduction to Database Systems DataLab CS, NTHU

Introduction to Relational Database Management Systems

Lecture 9&10 JDBC. Mechanism. Some Warnings. Notes. Style. Introductory Databases SSC Introduction to DataBases 1.

JDBC 3.0. Java Database Connectivity. 1 Java

Accessing a database from Java. Using JDBC

JDBC Architecture. JDBC API: This provides the application-to- JDBC Manager connection.

1) Consider the following code segment, applied to list, an ArrayList of Integer values.

HL7 FHIR Data Consolidation Tool

Web Applications and Database Connectivity using JDBC (Part II)

EAST WEST UNIVERSITY

Chapter 1 An introduction to relational databases and SQL

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Transcription:

INTERNATIONAL UNIVERSITY HCMC PROGRAMMING METHODOLOGY NONG LAM UNIVERSITY Instructor: Dr. Le Thanh Sach FACULTY OF IT WEBSITE SPECIAL SUBJECT Student-id: Instructor: LeMITM04015 Nhat Tung Course: IT.503 Start date: 2012 11-21 Student-name: Le Nhat Tung WEB SERVICES EXAMPLE 2 1. REQUIREMENTS: Building a dynamic web application (J2EE), it support web-services to other website. The web-services client can call a method to get list of student based on class -id. getstudents(string class_id) Web-service-server Web-service-client return ArrayList<Student> STUDENT TABLE 2. PREPARE TOOL & DATABASE: - JDK - Java development kit http://www.oracle.com/technetwork/java/javase/downloads/index.html - IDE: Eclipse support J2EE - http://www.eclipse.org/downloads/ - Web-server: Apache Tomcar v6.0 or v7.0 - http://tomcat.apache.org/ - Web-services: Apache Axis2 - http://axis.apache.org/axis2/java/core/ - DBMS: www.mysql.com/ + MySQL 5.0 + Mysql-connector (Mysql JDBC Driver) DBMS

2.1. Add the location of APACHE AXIS2 to eclipse: Step 1: Choose menu Window on Eclipse => Preferences Step 2: Choose Web Services => Axis2 Preferences => Fill the location of Axis 2 => Click OK button. The location of Axis2

2.2 Create database - Create a database (You must remember username, password and database name for connect from web application to DBMS) - Create table Student: 3. CREATE A WEB APPLICATION Step 1:

Step 2: You should choose version 2.5 Step 3: - Create model pakage and create clas Student:

package model; public class Student { private String STUDENT_ID, CLASS_ID, STUDENT_NAME, STUDENT_ADDRESS, STUDENT_PHONE; public Student() { public Student(String student_id, String class_id, String student_name, String student_address, String student_phone) { STUDENT_ID = student_id; CLASS_ID = class_id; STUDENT_NAME = student_name; STUDENT_ADDRESS = student_address; STUDENT_PHONE = student_phone; public String getstudent_id() { return STUDENT_ID; public void setstudent_id(string student_id) { STUDENT_ID = student_id; public String getclass_id() { return CLASS_ID; public void setclass_id(string class_id) { CLASS_ID = class_id; public String getstudent_name() { return STUDENT_NAME; public void setstudent_name(string student_name) { STUDENT_NAME = student_name; public String getstudent_address() { return STUDENT_ADDRESS; public void setstudent_address(string student_address) { STUDENT_ADDRESS = student_address; public String getstudent_phone() { return STUDENT_PHONE; This method support to print all information of Student public void setstudent_phone(string student_phone) { STUDENT_PHONE = student_phone; @Override public String tostring() { return "Student [STUDENT_ID=" + STUDENT_ID + ", CLASS_ID=" + CLASS_ID + ", STUDENT_NAME=" + STUDENT_NAME + ", STUDENT_ADDRESS=" + STUDENT_ADDRESS + ", STUDENT_PHONE=" + STUDENT_PHONE + "]";

Step 4: Connect to database - Create class DBConnection to connect from Web application to DBMS (remember you must add JDBC driver into project. package model; import java.sql.connection; import java.sql.drivermanager; public class DBConnection { public static Connection getconnection() { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); String url = "jdbc:mysql://localhost/school"; String user = "root"; String pass = "khongcopass"; connection = DriverManager.getConnection(url, user, pass); catch (ClassNotFoundException e) { // No driver err e.printstacktrace(); catch (SQLException e) { // Can not connect e.printstacktrace(); catch (Exception e) { // Orther err e.printstacktrace(); return connection; public static void main(string[] args) { System.out.println(getConnection()); 4. CREATE SERVICE S IMPLEMENTATION - Create class StudentDAO, it is a data access object class. In this class we create method getstudents(string class_id) to get list of student from DBMS based on class -id. package model; import import import import java.sql.connection; java.sql.preparedstatement; java.sql.resultset; java.util.arraylist; public class StudentDAO { public ArrayList<Student> getstudents(string class_id) { ArrayList<Student> list = new ArrayList<Student>(); try { // Get Connection Connection connection = DBConnection.getConnection(); // Execute query to get records from table Student String sql = "SELECT * FROM Student WHERE CLASS_ID=?"; PreparedStatement pr = connection.preparestatement(sql); pr.setstring(1, class_id); // Read all records from ResultSet, create object and add into list

ResultSet resultset = pr.executequery(); while (resultset.next()) { String STUDENT_ID = resultset.getstring("student_id"); String CLASS_ID = resultset.getstring("class_id"); String STUDENT_NAME = resultset.getstring("student_name"); String STUDENT_ADDRESS = resultset.getstring("student_address"); String STUDENT_PHONE = resultset.getstring("student_phone"); Student st = new Student(STUDENT_ID, CLASS_ID, STUDENT_NAME, STUDENT_ADDRESS, STUDENT_PHONE); list.add(st); // Close Connection connection.close(); catch (Exception e) { e.printstacktrace(); return list; 5. GENERATE WEB SERVICE Step 1: Right click on StudentDAO class => Choose New => Choose Other

Step 2: Choose Web service and click Next button Step 3: Click and change Web service runtime into Apache Axis2

Step 4: Run Apache Axis2

Click StudentDao to get file wsdl Link of dilw wsdl

6. CREATE SERVICE S CLIENT Step 1: Create a new web application

Step 2: Right click on WS_Example2_Client => choose New => Choose Other Step 3: Choose Web Service client and click Next

Step 4: Fill the link of file wsdl and change web service runtime. Link of file wsdl Change Webservice runtime into Apache Axis2 Step 5: - Create a class Student_client to call method package model; import java.rmi.remoteexception; import model.studentdaostub.student; import org.apache.axis2.axisfault;

public class Student_client { public static void main(string[] args) { try { StudentDAOStub servicesstub = new StudentDAOStub(); StudentDAOStub.GetStudents getstudents = new StudentDAOStub.GetStudents(); getstudents.setclass_id("mitm04"); StudentDAOStub.GetStudentsResponse getstudentsresponse = servicesstub.getstudents(getstudents); Student[] result = getstudentsresponse.get_return(); for (int i = 0; i < result.length; i++) { Student st = result[i]; System.out.println(st.getSTUDENT_ID() + " - " + st.getstudent_name() + " - " + st.getclass_id()); catch (AxisFault e) { // TODO Auto-generated catch block e.printstacktrace(); catch (RemoteException e) { // TODO Auto-generated catch block e.printstacktrace(); - The end of example 2Thank for your reading