JDeveloper 11g's REST web services - SAGE Computing Services by pengxiuhui

VIEWS: 141 PAGES: 82

									                 SAGE Computing Services
                 Customised Oracle Training Workshops and
                   Consulting




  JDeveloper 11g's REST web services

                    ....A change is as good as a REST




Chris Muir                         http://one-size-doesnt-fit-all.blogspot.com
Oracle Consultant and Trainer       Oracle ACE Director - Fusion Middleware
                    Agenda


• Part I: ABCs of Web Services
• Part II: REST Web Services in a Nutshell
• Part III: Getting your hands dirty with code
                                      Part I:
                                    Web Services




Photo thanks to Lexnger@ Flickr.com under CC
What are Web Services?


  The W3C defines a "web service" as "a
  software system designed to support
  interoperable machine-to-machine
  interaction over a network.”




                                          The traditional “Enterprise” view
The Traditional “Enterprise” View




         Images thanks to Harwan @ IconArchive.com – free for non commercial use   The contemporary view
The “Contemporary” View




     Images thanks to Harwan @ IconArchive.com – free for non commercial use   Key benefits
Key Benefits?

                 •       Share data (near realtime)
                 •       System interoperability
                 •       Low cost internet delivery
                 •       Standardized
                 •       Loosely coupled




  Photo thanks to vernhart@ Flickr.com under CC   History
                                                                   History?
       RFC-707 A High Level Framework for Network Based Resource Sharing
                             (Remote Procedure Call)

                                                                           Microsoft DCOM
                                                        Java RMI


                                                                   CORBA


                                                                     SOAP RPC Style


                                                                               SOAP Document Style


                                                                                                     REST


IETF – Internet Engineering Task Fask – ISOC – Internet Society                                             Choice
                        SOAP vs REST

Enterprise Ready                  Programmer Friendly
•   Supports multiple protocols   •   Only over HTTP
•   Contract first                •   Verb first (only 4 commands)
•   Procedural (RPC) based
                                  •   Simple
•   Standardized
•   Maximum security              •   Familiar

• Ideal for SOA support           •   Overly simplistic security
                                  •   Not 100% ideal for SOA
• Over engineered
                                  •   Little standardization
• Simple solutions become
  complicated                     •   No emphasis on contract
• Complex security
• Payload inefficiency


                                                             Part II – REST Web Services in a Nutshell
                                              Part II:
                                            REST Web
                                           Services in a
                                             Nutshell



Photo thanks to Caucas' @ Flickr.com under CC              What is REST?
Q: What is REST?
A: It stands for Representational State Transfer

Q: Huh? Can you say that in English?
A: Let me explain, do you surf the web?

Q: Um, yes I do (I thought I was asking the questions)....?
A: Then you already know it.




                                                              Browser/URL
Understand basics of HTTP
        The Request – HTTP Protocol
GET /about_sage_computing_services.html HTTP/1.1

Host: www.sagecomputing.com.au

User-Agent: Mozilla/5.0 Gecko/20100914 Firefox/3.6.10
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cookie: __utma=4761137.486424683.1273755779.1285256345.1285459361.13;;
If-Modified-Since: Sun, 31 Jan 2010 13:35:33 GMT
If-None-Match: "1a690fe-40df-f1645340" Cache-Control: max-age=0



 HTTP         GET/PUT/POST/DELETE                                                          URIs    Accept
                         Images thanks to Harwan @ IconArchive.com – free for non commercial use        HTTP Response
       The Response - HTTP Protocol
HTTP/1.1 200 OK

Date: Sun, 26 Sep 2010 00:02:25 GMT
Server: Apache/2.0.55 (Ubuntu)
Connection: Keep-Alive
Keep-Alive: timeout=15, max=96
Etag: "1a690fe-40df-f1645340“

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en“>
 <head>
   <title>SAGE Computing Services - About us</title
 </head>
 .... Etc ....
</html>



HTTP Error Codes                                 Payload/Body
                         Images thanks to Harwan @ IconArchive.com – free for non commercial use   Part II – REST Web Services in a Nutshell
   REST Web Services in a Nutshell

• REST also suits web services

• Resources – URIs = intuitive by
  design – gives users & developers
  ability to anticipate design

• Based on HTTP verbs –
  get/put/post/delete = simple to
  understand

• Stateless = scalable

                     Photo thanks to blitzmaerker @ Flickr.com under CC   Support for REST Web Services
Support?




           JAX-RS Jersey Website
Java JAX-RS “Jersey”




                       JAX-RS in detail
            Java JAX-RS & Jersey

•    JAX-RS Specification (API)
•   Introduced Java SE 5.0
•   Uses a simplified POJO approach
•   Implements both the client and/or server
•   Jersey is Oracle/Sun’s Reference Implementation

• Jersey 1.0 – 1.0.3 = JAX-RS 1.0 Spec
• Jersey 1.1+ = JAX-RS 1.2 Spec

                                                 Oracle JDeveloper 11g
       Oracle’s JDeveloper 11g

• Recommended version 11.1.1.3.0+
• Many minor issues in earlier versions
• Jersey 1.1.5.1+ supported (latest none beta
  1.4)
• http://one-size-doesnt-fit-
  all.blogspot.com/2010/10/rest-web-services-
  in-oracles-jdeveloper.html


                                      Part III – Getting your hands dirty with code
                                                  Part III:
                                                Getting your
                                                hands dirty
                                                 with code



Photo thanks to Caucas' @ Flickr.com under CC            Database “Departments” query
HTML Output/Browser
Data is Beautiful
Sad iPhone
Data
01 <html>
02 <head>
03   <style type="text/css">
04    table {background-color:#F2F2F5;}
05    td {color:#000000; font-family:Arial; padding:8px; background-color:#F2F2F5;}
06    th {font-family:Arial; font-size:12pt; padding:8px; background-color:#CFE0F1;}
07   </style>
08 </head>
09 <body>
10   <table border="0" cellpadding="0" cellspacing="0">
11    <tr>
12     <th>DEPARTMENT_ID</th>
13     <th>DEPARTMENT_NAME</th>
14    </tr>
15    <tbody>
16     <tr> <td>10</td> <td>Administration</td>    </tr>
17     <tr> <td>20</td> <td>Marketing</td>         </tr>
18     <tr> <td>30</td> <td>Purchasing</td>        </tr>
19     <tr> <td>40</td> <td>Human Resources</td> </tr>
20     <tr> <td>50</td> <td>Shipping</td>          </tr>
21     <tr> <td>60</td> <td>IT</td>                </tr>
22     <tr> <td>70</td> <td>Public Relations</td> </tr>
23     <tr> <td>80</td> <td>Sales</td>             </tr>
24     <tr> <td>90</td> <td>Executive</td>         </tr>
25     <tr> <td>100</td> <td>Finance</td>          </tr>
26    </tbody>
27   </table>
28 </body>
29 </html>
30
31
32                                                                       HTML page – markup + data
01 <html>
02 <head>
03   <style type="text/css">
04    table {background-color:#F2F2F5;}
05    td {color:#000000; font-family:Arial; padding:8px; background-color:#F2F2F5;}
06    th {font-family:Arial; font-size:12pt; padding:8px; background-color:#CFE0F1;}
07   </style>
08 </head>
09 <body>
10   <table border="0" cellpadding="0" cellspacing="0">
11    <tr>
12     <th>DEPARTMENT_ID</th>
13     <th>DEPARTMENT_NAME</th>
14    </tr>
15    <tbody>
16     <tr> <td>10</td> <td>Administration</td>    </tr>
17     <tr> <td>20</td> <td>Marketing</td>         </tr>
18     <tr> <td>30</td> <td>Purchasing</td>        </tr>
19     <tr> <td>40</td> <td>Human Resources</td> </tr>
20     <tr> <td>50</td> <td>Shipping</td>          </tr>
21     <tr> <td>60</td> <td>IT</td>                </tr>
22     <tr> <td>70</td> <td>Public Relations</td> </tr>
23     <tr> <td>80</td> <td>Sales</td>             </tr>
24     <tr> <td>90</td> <td>Executive</td>         </tr>
25     <tr> <td>100</td> <td>Finance</td>          </tr>
26    </tbody>
27   </table>
28 </body>
29 </html>
30
31
32                                                                          HTML page - makrup
01 <html>
02 <head>
03   <style type="text/css">
04    table {background-color:#F2F2F5;}
05    td {color:#000000; font-family:Arial; padding:8px; background-color:#F2F2F5;}
06    th {font-family:Arial; font-size:12pt; padding:8px; background-color:#CFE0F1;}
07   </style>
08 </head>
09 <body>
10   <table border="0" cellpadding="0" cellspacing="0">
11    <tr>
12     <th>DEPARTMENT_ID</th>
13     <th>DEPARTMENT_NAME</th>
14    </tr>
15    <tbody>
16     <tr> <td>10</td> <td>Administration</td>    </tr>
17     <tr> <td>20</td> <td>Marketing</td>         </tr>
18     <tr> <td>30</td> <td>Purchasing</td>        </tr>
19     <tr> <td>40</td> <td>Human Resources</td> </tr>
20     <tr> <td>50</td> <td>Shipping</td>          </tr>
21     <tr> <td>60</td> <td>IT</td>                </tr>
22     <tr> <td>70</td> <td>Public Relations</td> </tr>
23     <tr> <td>80</td> <td>Sales</td>             </tr>
24     <tr> <td>90</td> <td>Executive</td>         </tr>
25     <tr> <td>100</td> <td>Finance</td>          </tr>
26    </tbody>
27   </table>
28 </body>
29 </html>
30
31
32                                                                            Data – 1 per line
10
Administration
20
Marketing
30
Purchasing
40
Human Resources
50
Shipping
60
IT
70
Public Relations
80
Sales
90
Executive
100
Finance


                   Data – comma delimiited
DEPARTMENT_ID,DEPARTMENT_NAME
10,Administration
20,Marketing
30,Purchasing
40,Human Resources
50,Shipping
60,IT
70,Public Relations
80,Sales
90,Executive
100,Finance




                                Data - XML
<DEPARTMENTS>
 <DEPT><DEPTID>10</DEPTID><NAME>Administration</NAME></DEPT>
 <DEPT><DEPTID>20</DEPTID><NAME>Marketing</NAME></DEPT>
 <DEPT><DEPTID>30</DEPTID><NAME>Purchasing</NAME></DEPT>
 <DEPT><DEPTID>40</DEPTID><NAME>Human Resources</NAME></DEPT>
 <DEPT><DEPTID>50</DEPTID><NAME>Shipping</NAME></DEPT>
 <DEPT><DEPTID>60</DEPTID><NAME>IT</NAME></DEPT>
 <DEPT><DEPTID>70</DEPTID><NAME>Public Relations</NAME></DEPT>
 <DEPT><DEPTID>80</DEPTID><NAME>Sales</NAME></DEPT>
 <DEPT><DEPTID>90</DEPTID><NAME>Executive</NAME></DEPT>
 <DEPT><DEPTID>100</DEPTID><NAME>Finance</NAME></DEPT>
</DEPARTMENTS>




                                                      Building a REST Web Service
Building a REST Web Service




                              And now for a bit of Java
       And now for a bit of Java




JDBC – Java API for Database Connectivity
01 public class DepartmentsResource {
02
03 public static String queryDepartmentsSQL() throws SQLException {
04   Connection jdbcConn =
05    DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
06
07   String query = "SELECT department_id, department_name FROM departments";
08   Statement statement = jdbcConn.createStatement();
09   ResultSet resultSet = statement.executeQuery(query);
10
11   String result = "";
12   while (resultSet.next()) {
13    result = result + resultSet.getInt(1) + "\n";
14    result = result + resultSet.getString(2) + "\n";
15   }
16   statement.close();
17   jdbcConn.close();
18
19   return result;
20 }
21
22 public static void main(String[] args) throws SQLException {
23   String result = DepartmentsResource.queryDepartmentsSQL();
24   System.out.println(result);
25 }
26 }



RESTDemo3/Project1
RESTDemo3/Project1
01 @Path("/Departments")
02 public class DepartmentsResource {
03
04 public static String queryDepartmentsSQL() throws SQLException {
05   Connection jdbcConn =
06    DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
07
08   String query = "SELECT department_id, department_name FROM departments";
09   Statement statement = jdbcConn.createStatement();
10   ResultSet resultSet = statement.executeQuery(query);
11
12   String result = "";
13   while (resultSet.next()) {
14    result = result + resultSet.getInt(1) + "\n";
15    result = result + resultSet.getString(2) + "\n";
16   }
17   statement.close();
18   jdbcConn.close();
19
20   return result;
21 }
22
23 @GET
24 @Produces("plain/text")
25 public String getDepartments() throws SQLException {
26   return DepartmentsResource.queryDepartmentsSQL();
27 }
28 }

RESTDemo3/Project2
You are now REST certified




                         Make solution more Object Oriented
POJO
And now for some more Java




     A Plain Old Java Object


                               POJO code
01 public class Department {
02
03 private int deptId;
04 private String name;
05
06 public Department(int newDeptId, String newName) {
07   deptId = newDeptId;
08   name = newName;
09 }
10
11 public void setDeptId(int newDeptId) {
12   deptId = newDeptId;
13 }
14
15 public int getDeptId() {
16   return deptId;
17 }
18
19 public void setName(String newName) {
20   name = newName;
21 }
22
23 public String getName() {
24   return name;
25 }
26 }


RESTDemo3/Project3
01 @Path("/Departments")
02 public class DepartmentsResource {
03
04 public static ArrayList<Department> queryDepartmentsSQL() throws SQLException {
05   Connection jdbcConn =
06     DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
07
08   String query = "SELECT department_id, department_name FROM departments";
09   Statement statement = jdbcConn.createStatement();
10   ResultSet resultSet = statement.executeQuery(query);
11
12   ArrayList<Department> departments = new ArrayList<Department>();
13   while (resultSet.next()) {
14     Department dept = new Department(resultSet.getInt(1), resultSet.getString(2));
15     departments.add(dept);
16   }
17   statement.close();
18   jdbcConn.close();
19
20   return departments;
21 }
22
23 @GET
24 @Produces("plain/text")
25 public String getDepartments() throws SQLException {
26   String result = "";
27   for (Department department : DepartmentsResource.queryDepartmentsSQL()) {
28     result = result + department.getDeptId() + "," + department.getName() + "\n";
29   }
30   return result;
31 }
32 } RESTDemo3/Project3
01 @Path("/Departments")
02 public class DepartmentsResource {
03
04 public static Department queryDepartmentSQL(int deptId) throws SQLException {
05   Connection jdbcConn =
06     DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
07
08   String query = "SELECT department_id, department_name FROM departments "
09                      + "WHERE department_id = ?";
10   PreparedStatement statement = jdbcConn.prepareStatement(query);
11   statement.setInt(1, deptId);
12   ResultSet resultSet = statement.executeQuery();
13
14   Department department = null;
15   if (resultSet.next())
16     department = new Department(resultSet.getInt(1), resultSet.getString(2));
17
18   statement.close();
19   jdbcConn.close();
20
21   return department;
22 }
23
24 @GET
25 @Path("/{dept_id}") // /Departments/{dept_id}
26 @Produces("plain/text")
27 public String getDepartment(@PathParam("dept_id") int deptId) throws SQLException
28   Department department = DepartmentsResource.queryDepartmentSQL(deptId);
29
30   return department.getDeptId() + "," + department.getName() + "\n";
31 }
32 } RESTDemo3/Project4
24      @GET
25      @Path("/{dept_id}")
26      @Produces("plain/text")
27      public String getDepartment(@PathParam("dept_id") int deptId) throws SQLException
28       Department department = DepartmentsResource.queryDepartmentSQL(deptId);
29
30        if (department == null)
31         throw new NotFoundException("Department ID " + deptId + " not found");
32
33       return department.getDeptId() + "," + department.getName() + "\n";
34      }




RESTDemo3/Project5
XML?
<DEPARTMENTS>
 <DEPT><DEPTID>10</DEPTID><NAME>Administration</NAME></DEPT>
 <DEPT><DEPTID>20</DEPTID><NAME>Marketing</NAME></DEPT>
 <DEPT><DEPTID>30</DEPTID><NAME>Purchasing</NAME></DEPT>
 <DEPT><DEPTID>40</DEPTID><NAME>Human Resources</NAME></DEPT>
 <DEPT><DEPTID>50</DEPTID><NAME>Shipping</NAME></DEPT>
 <DEPT><DEPTID>60</DEPTID><NAME>IT</NAME></DEPT>
 <DEPT><DEPTID>70</DEPTID><NAME>Public Relations</NAME></DEPT>
 <DEPT><DEPTID>80</DEPTID><NAME>Sales</NAME></DEPT>
 <DEPT><DEPTID>90</DEPTID><NAME>Executive</NAME></DEPT>
 <DEPT><DEPTID>100</DEPTID><NAME>Finance</NAME></DEPT>
</DEPARTMENTS>
01 import javax.xml.bind.annotation.*;
02
03 @XmlAccessorType(XmlAccessType.FIELD)
04 @XmlType(name = "", propOrder = { "deptId", "name" })
05 @XmlRootElement(name = "DEPT")
06 public class Department {
07
08      @XmlElement(name = "DEPTID", required = true)
09      private int deptId;
10      @XmlElement(name = "NAME", required = true)
11      private String name;
12
13      public Department() { } // default no-arg constructor required for JAXB
14
15      public Department(int newDeptId, String newName) {
16        deptId = newDeptId;
17        name = newName;
18      }
19
20      public void setDeptId(int newDeptId) { deptId = newDeptId; }
21
22      public int getDeptId() { return deptId; }
23
24      public void setName(String newName) { name = newName; }
25
26      public String getName() { return name; }
27 }
28
29
30
31
32 RESTDemo3/Project6
01   @GET
02   // @Path("/Departments")
03   @Produces("plain/text")
04   public String getDepartments() throws SQLException {
05    String result = "";
06    for (Department department : DepartmentResources.queryDepartmentsSQL()) {
07     result = result + department.getDeptId() + "," + department.getName() + "\n";
08    }
09    return result;
10   }
11
12   @GET
13   @Path("/{dept_id}") // /Departments/{dept_id}
14   @Produces("plain/text")
15   public String getDepartment(@PathParam("dept_id") int deptId) throws SQLException {
16    Department department = DepartmentResources.queryDepartmentSQL(deptId);
17    if (department == null)
18     throw new NotFoundException("Department ID " + deptId + " not found");
19
20    return department.getDeptId() + "," + department.getName() + "\n";
21   }
22
23   @GET
24   @Path("/{dept_id}") // /Departments/{dept_id}
25   @Produces("application/xml")
26   public Department getDepartmentXML(@PathParam("dept_id") int deptId) throws SQLExce
27    Department department = DepartmentResources.queryDepartmentSQL(deptId);
28    if (department == null)
29     throw new NotFoundException("Department ID " + deptId + " not found");
30
31    return department;
32   } RESTDemo3/Project6
01   @GET
02   // @Path("/Departments")
03   @Produces("plain/text")
04   public String getDepartments() throws SQLException {
05    String result = "";
06    for (Department department : DepartmentsResource.queryDepartmentsSQL()) {
07     result = result + department.getDeptId() + "," + department.getName() + "\n";
08    }
09    return result;
10   }
11
12   @GET
13   @Path("/{dept_id}") // /Departments/{dept_id}
14   @Produces("plain/text")
15   public String getDepartment(@PathParam("dept_id") int deptId) throws SQLException {
16    Department department = DepartmentsResource.queryDepartmentSQL(deptId);
17    if (department == null)
18     throw new NotFoundException("Department ID " + deptId + " not found");
19
20    return department.getDeptId() + "," + department.getName() + "\n";
21   }
22
23   @GET
24   @Path("/{dept_id}") // /Departments/{dept_id}
25   @Produces("application/xml")
26   public Department getDepartmentXML(@PathParam("dept_id") int deptId) throws SQLExce
27    Department department = DepartmentsResource.queryDepartmentSQL(deptId);
28    if (department == null)
29     throw new NotFoundException("Department ID " + deptId + " not found");
30
31    return department;
32   } RESTDemo3/Project6
<DEPARTMENTS>
 <DEPT><DEPTID>10</DEPTID><NAME>Administration</NAME></DEPT>
 <DEPT><DEPTID>20</DEPTID><NAME>Marketing</NAME></DEPT>
 <DEPT><DEPTID>30</DEPTID><NAME>Purchasing</NAME></DEPT>
 <DEPT><DEPTID>40</DEPTID><NAME>Human Resources</NAME></DEPT>
 <DEPT><DEPTID>50</DEPTID><NAME>Shipping</NAME></DEPT>
 <DEPT><DEPTID>60</DEPTID><NAME>IT</NAME></DEPT>
 <DEPT><DEPTID>70</DEPTID><NAME>Public Relations</NAME></DEPT>
 <DEPT><DEPTID>80</DEPTID><NAME>Sales</NAME></DEPT>
 <DEPT><DEPTID>90</DEPTID><NAME>Executive</NAME></DEPT>
 <DEPT><DEPTID>100</DEPTID><NAME>Finance</NAME></DEPT>
</DEPARTMENTS>
01    @XmlAccessorType(XmlAccessType.FIELD)
02    @XmlType(name = "", propOrder = { "departments" })
03    @XmlRootElement(name = "DEPARTMENTS")
04    public class Departments {
05
06        @XmlElement(name = "DEPT", required = true)
07        protected List<Department> departments;
08
09        public List<Department> getDepartments() {
10          if (departments == null) {
11            departments = new ArrayList<Department>();
12          }
13          return this.departments;
14        }
15    }




RESTDemo3/Project7
01    public static Departments queryDepartmentsSQL() throws SQLException {
02     Connection jdbcConn =
03      DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:home","hr","hr");
04
05      String query = "SELECT department_id, department_name FROM departments";
06      Statement statement = jdbcConn.createStatement();
07      ResultSet resultSet = statement.executeQuery(query);
08
09      Departments departments = new Departments();
10      List<Department> departmentList = departments.getDepartments();
11
12      while (resultSet.next()) {
13       Department dept = new Department(resultSet.getInt(1), resultSet.getString(2));
14       departmentList.add(dept);
15      }
16      statement.close();
17      jdbcConn.close();
18
19     return departments;
20    }
21
22    @GET
23    @Produces("application/xml")
24    public Departments getDepartmentsXML() throws SQLException {
25     return DepartmentsResource.queryDepartmentsSQL();
26    }




RESTDemo3/Project7
01    public static void insertDepartmentSQL(int deptId, String name)
02      throws SQLException {
03
04      Connection jdbcConn =
05       DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
06
07      String insert = "INSERT INTO departments (department_id, department_name) "
08                    + "VALUES (?, ?)";
09
10      PreparedStatement statement = jdbcConn.prepareStatement(insert);
11      statement.setInt(1, deptId);
12      statement.setString(2, name);
13      boolean result = statement.execute();
14      jdbcConn.commit();
15
16        statement.close();
17        jdbcConn.close();
18    }
19
20    @POST
21    @Path("/{dept_id}")
22    public void insertDepartment(@PathParam("dept_id") int deptId
23                                ,@FormParam("name") String name)
24      throws SQLException {
25
26     DepartmentsResource.insertDepartmentSQL(deptId, name);
27    }




RESTDemo3/Project8
01    public static void updateDepartmentSQL(int deptId, String name)
02      throws SQLException {
03
04      Connection jdbcConn =
05       DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
06
07      String update = "UPDATE departments SET department_name = ? "
08                    + "WHERE department_id = ?";
09
10      PreparedStatement statement = jdbcConn.prepareStatement(update);
11      statement.setString(1, name);
12      statement.setInt(2, deptId);
13      boolean result = statement.execute();
14      jdbcConn.commit();
15
16     statement.close();
17     jdbcConn.close();
18    }
19
20    @PUT
21    @Path("/{dept_id}")
22    public void updateDepartment(@PathParam("dept_id") int deptId
23                                ,@FormParam("name") String name)
24      throws SQLException {
25
26     DepartmentsResource.updateDepartmentSQL(deptId, name);
27    }




RESTDemo3/Project8
01    public static void deleteDepartmentSQL(int deptId)
02      throws SQLException {
03
04      Connection jdbcConn =
05       DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
06
07      String delete = "DELETE departments WHERE department_id = ?";
08
09      PreparedStatement statement = jdbcConn.prepareStatement(delete);
10      statement.setInt(1, deptId);
11      boolean result = statement.execute();
12      jdbcConn.commit();
13
14     statement.close();
15     jdbcConn.close();
16    }
17
18    @DELETE
19    @Path("/{dept_id}")
20    public void deleteDepartment(@PathParam("dept_id") int deptId)
21      throws SQLException {
22
23     DepartmentsResource.deleteDepartmentSQL(deptId);
24    }




RESTDemo3/Project8
    (Part IV The stuff I didn’t cover)
•   HATEOAS
•   Security
•   JSON
•   WADL
•   Designing REST web services
"Any intelligent fool can make things bigger, more complex, and more
violent. It takes a touch of genius -- and a lot of courage -- to move in
the opposite direction.“

-- Albert Einstein
SAGE Computing Services
Customised Oracle Training Workshops and
  Consulting




Questions and Answers?
Presentations are available from our website:
www.sagecomputing.com.au

enquiries@sagecomputing.com.au
chris.muir@sagecomputing.com.au
http://one-size-doesnt-fit-all.blogspot.com
Twitter: chriscmuir
Linkedin: http://au.linkedin.com/in/chriscmuir

								
To top