Chris Pollett > Students >
Rekha

    ( Print View )

    [Bio]

    [CS297Proposal]

    [Del1]

    [Del2]

    [Del3]

    [Del4]

    [CS297 Report-PDF]

    [CS298 Proposal]

    [CS298 Presentation-PDF]

    [Game Description-PDF]

    [Final Game-ZIP]

    [CS298 Report-PDF]

                          

























Deliverable 4

Description: This is the extension of the Deliverable Three which shows the connection from the HTTP Server to the Oracle Database in which the XML document gets stored.

/**

   COPYRIGHT (C) 2003 Rekha Vaddepalli.

   Class to do the functionality of the HTTP Server.
   This class gets the information(i.e., XML form) from the Pocket PC
   and connects to the Oracle database and stores it.

   Solves Deliverable 2

   @author Rekha Vaddepalli

   @version 1.00 2003/11/15

*/

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.StringBuffer;
import java.io.IOException;
import java.sql.*;
import oracle.jdbc.driver.*;

public class XMLOracleservlet extends HttpServlet
{
/**

   Do the HTTP POST. It gets the data from the Pocket PC,
   gets the connection to the
   Oracle database, and stores the information in the database.

   @param request HttpServletRequest

   @param response HttpServletResponse

*/

public void doPost(HttpServletRequest request,HttpServletResponse response)
  throws IOException,ServletException
  {

    /* Get the input stream and read the data */
    ServletInputStream in = request.getInputStream();
    DataInputStream    din = new DataInputStream( in );

    String text = din.readUTF();
    din.close();

    Connection connection=null;
    Statement statement=null;
    response.setContentType("text/html");

    StringBuffer sb = new 	StringBuffer(text);
    StringBuffer sqlXml = new 	StringBuffer();

    /* To get the connection to the database*/
    try {
	String driverName = "oracle.jdbc.driver.OracleDriver";
	Class.forName(driverName);
    } catch(ClassNotFoundException ej){
	ej.printStackTrace();
    }
    /* To register the driver*/
    try {
	DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    } catch (Exception e) {
	e.printStackTrace();
    }

    /* To submit the information to the Oracle Database*/
    String username="scott", password="tiger",
    dbURL="jdbc:oracle:thin:@anouki:1521:ORA9IDB";

    try{
	connection=DriverManager.getConnection(dbURL,username,password);
	statement=connection.createStatement();
	System.out.println(sb);
	sqlXml.append("insert into BABY_BOOK_ENTRIES values (xmltype('" );
      sqlXml.append("<baby xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
      xsi:noNamespaceSchemaLocation= \"baby.xsd\"> ");
	sqlXml.append(sb);
	sqlXml.append("</baby>");
	sqlXml.append("'))");
	System.out.println(sqlXml.toString());
	statement.executeUpdate(sqlXml.toString());
	statement.close();
	connection.close();
    } catch(Exception ex){
	System.out.println("Problem problem problem");
	System.err.println("SQLException: " + ex.getMessage());
	ex.printStackTrace();
    }
    /* To form the response and send it back to the Pocket PC*/
    response.setStatus( response.SC_OK );
    ServletOutputStream out = response.getOutputStream();
    out.close();
  }
}