Example #1
0
  public static void recieveTrafficRates(String IP, float upload, float download) {
    System.out.println("Insertion of Data into Database!");
    Connection con = null;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "traffic_report";
    String driverName = "com.mysql.jdbc.Driver";
    String userName = "******";
    String password = "******";
    String IP_address = IP;

    float up = upload, down = download;

    try {
      Class.forName(driverName).newInstance();
      con = DriverManager.getConnection(url + dbName, userName, password);
      try {
        Statement st = con.createStatement();

        int val =
            st.executeUpdate(
                "INSERT current_traffic VALUES('" + IP + "','" + up + "','" + down + "')");

        System.out.println("Data Entry process successfully!");
      } catch (SQLException s) {
        System.out.println("Table all ready exists!" + s);
      }
      con.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  /**
   * Establishes a connection to a registry.
   *
   * @param queryUrl the URL of the query registry
   * @param publishUrl the URL of the publish registry
   */
  public void makeConnection(String queryUrl, String publishUrl) {

    Context context = null;
    ConnectionFactory factory = null;

    /*
     * Define connection configuration properties.
     * To publish, you need both the query URL and the
     * publish URL.
     */
    Properties props = new Properties();
    props.setProperty("javax.xml.registry.queryManagerURL", queryUrl);
    props.setProperty("javax.xml.registry.lifeCycleManagerURL", publishUrl);

    try {
      // Create the connection, passing it the
      // configuration properties
      context = new InitialContext();
      factory = (ConnectionFactory) context.lookup("java:comp/env/eis/JAXR");
      factory.setProperties(props);
      connection = factory.createConnection();
      System.out.println("Created connection to registry");
    } catch (Exception e) {
      e.printStackTrace();
      if (connection != null) {
        try {
          connection.close();
        } catch (JAXRException je) {
        }
      }
    }
  }
Example #3
0
 public void dispose() {
   try {
     stmt.close();
     con.close();
   } catch (SQLException e) {
   }
 }
Example #4
0
  public void login() {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:orcl";
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

    String id, pw, sql;
    try {
      Class.forName(driver);
      con = DriverManager.getConnection(url, "hr", "hr");
      stmt = con.createStatement();
      sql = "select * from chatuser where id = '" + lid.getText() + "'";
      rs = stmt.executeQuery(sql);
      if (rs.next()) {
        pw = rs.getString(2);
        nick = rs.getString(3);
        if (lpw.getText().equals(pw)) {
          jd.setVisible(false);
          setVisible(true);
        } else {
          lpw.setText("일치하지 않습니다.");
        }
      } else {
        lid.setText("일치하지 않습니다.");
      }
    } catch (Exception e1) {
      e1.printStackTrace();
      System.out.println("데이터 베이스 연결 실패!!");
    } finally {
      try {
        if (rs != null) rs.close();
        if (stmt != null) stmt.close();
        if (con != null) con.close();
      } catch (Exception e1) {
        System.out.println(e1.getMessage());
      }
    }
  }
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    HttpSession session = request.getSession(true);

    try {
      Object accountObject = session.getValue(ACCOUNT);

      // If no account object was put in the session, or
      // if one exists but it is not a hashtable, then
      // redirect the user to the original login page

      if (accountObject == null)
        throw new RuntimeException("You need to log in to use this service!");

      if (!(accountObject instanceof Hashtable))
        throw new RuntimeException("You need to log in to use this service!");

      Hashtable account = (Hashtable) accountObject;

      String userName = (String) account.get("name");

      //////////////////////////////////////////////
      // Display Messages for the user who logged in
      //////////////////////////////////////////////
      out.println("<HTML>");
      out.println("<HEAD>");
      out.println("<TITLE>Contacts for " + userName + "</TITLE>");
      out.println("</HEAD>");
      out.println("<BODY BGCOLOR='#EFEFEF'>");
      out.println("<H3>Welcome " + userName + "</H3>");

      out.println("<CENTER>");

      Connection con = null;
      Statement stmt = null;
      ResultSet rs = null;
      try {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        con =
            DriverManager.getConnection(
                "jdbc:mysql://localhost/contacts?user=kareena&password=kapoor");

        stmt = con.createStatement();
        rs =
            stmt.executeQuery(
                "SELECT * FROM contacts WHERE userName='******' ORDER BY contactID");

        out.println("<form name='deleteContactsForm' method='post' action='deleteContact'>");

        out.println("<TABLE BGCOLOR='#EFEFFF' CELLPADDING='2' CELLSPACING='4' BORDER='1'>");
        out.println("<TR BGCOLOR='#D6DFFF'>");
        out.println("<TD ALIGN='center'><B>Contact ID</B></TD>");
        out.println("<TD ALIGN='center'><B>Contact Name</B></TD>");
        out.println("<TD ALIGN='center'><B>Comment</B></TD>");
        out.println("<TD ALIGN='center'><B>Date</B></TD>");
        out.println("<TD ALIGN='center'><B>Delete Contacts</B></TD>");
        out.println("</TR>");

        int nRows = 0;
        while (rs.next()) {
          nRows++;
          String messageID = rs.getString("contactID");
          String fromUser = rs.getString("contactName");
          String message = rs.getString("comments");
          String messageDate = rs.getString("dateAdded");

          out.println("<TR>");
          out.println("<TD>" + messageID + "</TD>");
          out.println("<TD>" + fromUser + "</TD>");
          out.println("<TD>" + message + "</TD>");
          out.println("<TD>" + messageDate + "</TD>");
          out.println(
              "<TD><input type='checkbox' name='msgList' value='" + messageID + "'> Delete</TD>");
          out.println("</TR>");
        }

        out.println("<TR>");
        out.println(
            "<TD COLSPAN='6' ALIGN='center'><input type='submit' value='Delete Selected Contacts'></TD>");
        out.println("</TR>");

        out.println("</TABLE>");
        out.println("</FORM>");
      } catch (Exception e) {
        out.println("Could not connect to the users database.<P>");
        out.println("The error message was");
        out.println("<PRE>");
        out.println(e.getMessage());
        out.println("</PRE>");
      } finally {
        if (rs != null) {
          try {
            rs.close();
          } catch (SQLException ignore) {
          }
        }
        if (stmt != null) {
          try {
            stmt.close();
          } catch (SQLException ignore) {
          }
        }
        if (con != null) {
          try {
            con.close();
          } catch (SQLException ignore) {
          }
        }
      }

      out.println("</CENTER>");
      out.println("</BODY>");
      out.println("</HTML>");

    } catch (RuntimeException e) {
      out.println("<script language=\"javascript\">");
      out.println("alert(\"You need to log in to use this service!\");");
      out.println("</script>");

      out.println("<a href='index.html'>Click Here</a> to go to the main page.<br><br>");

      out.println(
          "Or Click on the button to exit<FORM><INPUT onClick=\"javascipt:window.close()\" TYPE=\"BUTTON\" VALUE=\"Close Browser\" TITLE=\"Click here to close window\" NAME=\"CloseWindow\" STYLE=\"font-family:Verdana, Arial, Helvetica; font-size:smaller; font-weight:bold\"></FORM>");

      log(e.getMessage());
      return;
    }
  }
  /**
   * Creates an organization, its classification, and its services, and saves it to the registry.
   */
  public String executePublish(String username, String password, String endpoint) {

    String id = null;
    RegistryService rs = null;
    BusinessLifeCycleManager blcm = null;
    BusinessQueryManager bqm = null;

    try {
      rs = connection.getRegistryService();
      blcm = rs.getBusinessLifeCycleManager();
      bqm = rs.getBusinessQueryManager();
      System.out.println("Got registry service, query " + "manager, and life cycle manager");

      // Get authorization from the registry
      PasswordAuthentication passwdAuth =
          new PasswordAuthentication(username, password.toCharArray());

      Set creds = new HashSet();
      creds.add(passwdAuth);
      connection.setCredentials(creds);
      System.out.println("Established security credentials");

      // Get hardcoded strings from a ResourceBundle
      ResourceBundle bundle = ResourceBundle.getBundle("com.sun.cb.CoffeeRegistry");

      // Create organization name and description
      Organization org = blcm.createOrganization(bundle.getString("org.name"));
      InternationalString s = blcm.createInternationalString(bundle.getString("org.description"));
      org.setDescription(s);

      // Create primary contact, set name
      User primaryContact = blcm.createUser();
      PersonName pName = blcm.createPersonName(bundle.getString("person.name"));
      primaryContact.setPersonName(pName);

      // Set primary contact phone number
      TelephoneNumber tNum = blcm.createTelephoneNumber();
      tNum.setNumber(bundle.getString("phone.number"));
      Collection phoneNums = new ArrayList();
      phoneNums.add(tNum);
      primaryContact.setTelephoneNumbers(phoneNums);

      // Set primary contact email address
      EmailAddress emailAddress = blcm.createEmailAddress(bundle.getString("email.address"));
      Collection emailAddresses = new ArrayList();
      emailAddresses.add(emailAddress);
      primaryContact.setEmailAddresses(emailAddresses);

      // Set primary contact for organization
      org.setPrimaryContact(primaryContact);

      // Set classification scheme to NAICS
      ClassificationScheme cScheme =
          bqm.findClassificationSchemeByName(null, bundle.getString("classification.scheme"));

      // Create and add classification
      Classification classification =
          (Classification)
              blcm.createClassification(
                  cScheme,
                  bundle.getString("classification.name"),
                  bundle.getString("classification.value"));
      Collection classifications = new ArrayList();
      classifications.add(classification);
      org.addClassifications(classifications);

      // Create services and service
      Collection services = new ArrayList();
      Service service = blcm.createService(bundle.getString("service.name"));
      InternationalString is =
          blcm.createInternationalString(bundle.getString("service.description"));
      service.setDescription(is);

      // Create service bindings
      Collection serviceBindings = new ArrayList();
      ServiceBinding binding = blcm.createServiceBinding();
      is = blcm.createInternationalString(bundle.getString("service.binding"));
      binding.setDescription(is);
      binding.setValidateURI(false);
      binding.setAccessURI(endpoint);
      serviceBindings.add(binding);

      // Add service bindings to service
      service.addServiceBindings(serviceBindings);

      // Add service to services, then add services to organization
      services.add(service);
      org.addServices(services);

      // Add organization and submit to registry
      // Retrieve key if successful
      Collection orgs = new ArrayList();
      orgs.add(org);
      BulkResponse response = blcm.saveOrganizations(orgs);
      Collection exceptions = response.getExceptions();
      if (exceptions == null) {
        System.out.println("Organization saved");

        Collection keys = response.getCollection();
        Iterator keyIter = keys.iterator();
        if (keyIter.hasNext()) {
          javax.xml.registry.infomodel.Key orgKey =
              (javax.xml.registry.infomodel.Key) keyIter.next();
          id = orgKey.getId();
          System.out.println("Organization key is " + id);
        }
      } else {
        Iterator excIter = exceptions.iterator();
        Exception exception = null;
        while (excIter.hasNext()) {
          exception = (Exception) excIter.next();
          System.err.println("Exception on save: " + exception.toString());
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      if (connection != null) {
        try {
          connection.close();
        } catch (JAXRException je) {
          System.err.println("Connection close failed");
        }
      }
    }
    return id;
  }
Example #7
0
  @Override
  public int run() throws Exception {
    // Default values of command line arguments
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;
    String user = DEFAULT_USER;
    String pass = DEFAULT_PASS;
    String destination = DEFAULT_DESTINATION;
    String file = ""; // No default -- if not given, don't read/write file
    int sleep = 0;
    boolean showpercent = false;
    int batchSize = 0;
    int length = 500; // Length of message generated internally
    String properties = "";
    String format = "short";
    String durable = null;

    int n = 1; // n is the number of messages to process, or a specific
    //   message number, depending on content
    String url = ""; // No default -- if not given, don't use it

    String[] nonSwitchArgs = cl.getArgs();
    if (nonSwitchArgs.length > 0) n = Integer.parseInt(nonSwitchArgs[0]);

    String _destination = cl.getOptionValue("destination");
    if (_destination != null) destination = _destination;

    String _host = cl.getOptionValue("host");
    if (_host != null) host = _host;

    String _port = cl.getOptionValue("port");
    if (_port != null) port = Integer.parseInt(_port);

    String _file = cl.getOptionValue("file");
    if (_file != null) file = _file;

    String _user = cl.getOptionValue("user");
    if (_user != null) user = _user;

    String _pass = cl.getOptionValue("password");
    if (_pass != null) pass = _pass;

    String _url = cl.getOptionValue("url");
    if (_url != null) url = _url;

    String _sleep = cl.getOptionValue("sleep");
    if (_sleep != null) sleep = Integer.parseInt(_sleep);

    if (cl.hasOption("percent")) showpercent = true;

    String _batchSize = cl.getOptionValue("batch");
    if (_batchSize != null) batchSize = Integer.parseInt(_batchSize);

    String _L = cl.getOptionValue("length");
    if (_L != null) length = Integer.parseInt(_L);

    String _properties = cl.getOptionValue("properties");
    if (_properties != null) properties = _properties;

    String _durable = cl.getOptionValue("durable");
    if (_durable != null) durable = _durable;

    boolean batch = false;
    if (batchSize != 0) batch = true;

    String _format = cl.getOptionValue("format");
    if (_format != null) format = _format;

    ActiveMQConnectionFactory factory = getFactory(host, port, url);

    Connection connection = factory.createConnection(user, pass);

    if (durable != null) connection.setClientID(durable);

    connection.start();

    Session session = connection.createSession(batch, Session.AUTO_ACKNOWLEDGE);

    Topic topic = session.createTopic(destination);

    MessageConsumer consumer = null;
    if (durable != null) consumer = session.createDurableSubscriber(topic, "amqutil");
    else consumer = session.createConsumer(topic);

    int oldpercent = 0;
    for (int i = 0; i < n; i++) {
      javax.jms.Message message = consumer.receive();

      if (batch) if ((i + 1) % batchSize == 0) session.commit();

      if (sleep != 0) Thread.sleep(sleep);

      JMSUtil.outputMessage(format, message, file);

      if (showpercent) {
        int percent = i * 100 / n;
        if (percent != oldpercent) System.out.println("" + percent + "%");
        oldpercent = percent;
      }
    }

    if (batch) session.commit();

    connection.close();

    return 0;
  }
  /** Begin running the websocket server. */
  @Override
  public void run() {

    try {

      Logger.info(
          MessageFormat.format("WebSocketServerBridge listening on port {0}...", this.port));

      serverSocket = new ServerSocket(this.port);

      // Waiting for the server socket to close or until the server is shutdown manually.
      while ((this.isServerRunning) && (!serverSocket.isClosed())) {

        // Wait for incoming connections.
        Socket socket = serverSocket.accept();

        // Try to reclaim any threads if we are exceeding our maximum.
        // TimeComplexity: O(n) -- Where n is the number of threads valid or invalid.
        // NOTE: Minimal unit testing has been done here...more testing is required.
        if (threads.size() + 1 > this.getMaximumThreads()) {
          for (int i = 0; i < threads.size(); i++) {
            if (!threads.get(i).isAlive()) {
              threads.remove(i);
            }
          }
        }

        // Make sure we have enough threads before accepting.
        // NOTE: Minimal unit testing has been done here...more testing is required.
        if ((threads.size() + 1) <= this.getMaximumThreads()) {

          Connection t = new Connection(socket, this.serviceLayer, this);
          t.start();
          threads.add(t);

        } else {
          Logger.debug("The server has reached its thread maximum...");
        }
      }
      // END OF while ( (this.isServerRunning) && (!serverSocket.isClosed()) )...

      Logger.info("WebSocket server stopping...");

    } catch (IOException ioException) {

      // --- CR (8/10/13) --- Only log the event if the server is still running.  This should
      // prevent an error message from appearing when the server is restarted.
      if (this.isServerRunning) {

        Logger.info(
            MessageFormat.format("The port {0} could not be opened for WebSockets.", this.port));
        Logger.debug(ioException.getMessage());
      }

      // Close all threads.
      // TimeComplexity: O(n) -- Where n is the number of threads valid or invalid.
      for (Connection t : threads) {
        if (t.isAlive()) {
          t.close();
        }
      }
    }
  }
Example #9
0
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    ResultSet rs = null;
    try {
      // SET UP Context environment, to look for Data Pooling Resource
      Context initCtx = new InitialContext();
      Context envCtx = (Context) initCtx.lookup("java:comp/env");
      DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB");
      Connection dbcon = ds.getConnection();

      // ########### SEARCH INPUT PARAMETERS, EXECUTE search
      // #####################################################
      Vector<String> params = new Vector<String>();
      params.add(request.getParameter("fname"));
      params.add(request.getParameter("lname"));
      params.add(request.getParameter("title"));
      params.add(request.getParameter("year"));
      params.add(request.getParameter("director"));

      List<Movie> movies = new ArrayList<Movie>();
      movies = SQLServices.getMovies(params.toArray(new String[params.size()]), dbcon);

      // ########## SET DEFAULT SESSION() PARAMETERS ####################################
      request.getSession().removeAttribute("movies");
      request.getSession().removeAttribute("linkedListMovies");
      request.getSession().removeAttribute("hasPaged");
      request.getSession().setAttribute("hasPaged", "no");
      request.getSession().setAttribute("movies", movies);
      request.getSession().setAttribute("currentIndex", "0");
      request.getSession().setAttribute("defaultN", "5");

      // ########## IF MOVIES FROM SEARCH NON-EMPTY ###########################################
      List<String> fields = Movie.fieldNames();
      int count = 1;
      if (!movies.isEmpty()) {
        request.setAttribute("movies", movies);
        for (String field : fields) {
          request.setAttribute("f" + count++, field);
        }
        request.getRequestDispatcher("../movieList.jsp").forward(request, response);
      } else {
        out.println("<html><head><title>error</title></head>");
        out.println("<body><h1>could not find any movies, try your search again.</h1>");
        out.println("<p> we are terribly sorry, please go back. </p>");
        out.println("<table border>");
        out.println("</table>");
      }
      dbcon.close();

    } catch (SQLException ex) {
      while (ex != null) {
        System.out.println("SQL Exception:  " + ex.getMessage());
        ex = ex.getNextException();
      }
    } catch (java.lang.Exception ex) {
      out.println(
          "<html>"
              + "<head><title>"
              + "moviedb: error"
              + "</title></head>\n<body>"
              + "<p>SQL error in doGet: "
              + ex.getMessage()
              + "</p></body></html>");
      return;
    }
    out.close();
  }
Example #10
0
  private static void executeOS(
      String sourceType,
      String sourceServer,
      String sourceInstance,
      int sourcePort,
      String sourceDatabase,
      String sourceSchema,
      String sourceTable,
      String refreshType,
      String appendColumnName,
      int appendColumnMax,
      Connection gpConn,
      int queueId)
      throws Exception {
    String method = "executeOS";
    int location = 1000;

    String sourceUser = "";
    String sourcePass = "";
    String strSQL = "";
    int fetchSize = 10;
    Connection conn = null;

    try {
      location = 3000;

      ResultSet rs;
      Statement stmt;

      location = 3010;
      strSQL = GP.getQueueDetails(gpConn, queueId);

      location = 3020;
      stmt = gpConn.createStatement();

      location = 3040;
      rs = stmt.executeQuery(strSQL);

      while (rs.next()) {
        sourceUser = rs.getString(1);
        sourcePass = rs.getString(2);
      }

      location = 3090;
      if (sourceType.equals("sqlserver")) {
        location = 3100;
        conn = CommonDB.connectSQLServer(sourceServer, sourceInstance, sourceUser, sourcePass);

        location = 3200;
        // create SQL statement for selecting data
        strSQL =
            SQLServer.getSQLForData(
                conn,
                sourceDatabase,
                sourceSchema,
                sourceTable,
                refreshType,
                appendColumnName,
                appendColumnMax);

        location = 3300;
        // execute the SQL Statement
        CommonDB.outputData(conn, strSQL);

        location = 3400;
        conn.close();

      } else if (sourceType.equals("oracle")) {
        location = 4000;
        fetchSize = Integer.parseInt(GP.getVariable(gpConn, "oFetchSize"));

        location = 4100;
        conn =
            CommonDB.connectOracle(
                sourceServer, sourceDatabase, sourcePort, sourceUser, sourcePass, fetchSize);

        location = 4200;
        // execute the SQL Statement
        strSQL =
            Oracle.getSQLForData(
                conn, sourceSchema, sourceTable, refreshType, appendColumnName, appendColumnMax);

        location = 4300;
        // execute the SQL Statement
        CommonDB.outputData(conn, strSQL);

        location = 4400;
        conn.close();
      }

    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    } finally {
      if (conn != null) conn.close();
    }
  }
Example #11
0
  public static void main(String[] args) throws Exception {
    String method = "main";
    int location = 1000;
    int argsCount = args.length;

    String sourceType = "";
    String sourceServer = "";
    String sourceInstance = "";
    int sourcePort = 0;
    String sourceDatabase = "";
    String sourceSchema = "";
    String sourceTable = "";
    String refreshType = "";
    String appendColumnName = "";
    int appendColumnMax = 0;
    String gpDatabase = "";
    int gpPort = 0;
    int queueId = 0;
    int connectionId = 0;
    String selectSQL = "";

    // this is an external table that a user defines
    if (argsCount == 4) {
      gpDatabase = args[0];
      gpPort = Integer.parseInt(args[1]);
      connectionId = Integer.parseInt(args[2]);
      selectSQL = args[3];
    }
    // this is an extrenal table Outsourcer defines
    else if (argsCount == 13) {
      sourceType = args[0];
      sourceServer = args[1];
      sourceInstance = args[2];
      sourcePort = Integer.parseInt(args[3]);
      sourceDatabase = args[4];
      sourceSchema = args[5];
      sourceTable = args[6];
      refreshType = args[7];
      appendColumnName = args[8];
      appendColumnMax = Integer.parseInt(args[9]);
      gpDatabase = args[10];
      gpPort = Integer.parseInt(args[11]);
      queueId = Integer.parseInt(args[12]);
    }

    String gpServer = "localhost";
    String gpUserName = System.getProperty("user.name");
    String sourceUser = "";
    String sourcePass = "";
    Connection gpConn = null;

    try {
      location = 3000;
      gpConn = CommonDB.connectGP(gpServer, gpPort, gpDatabase, gpUserName);

      if (argsCount == 13) {
        location = 3100;
        executeOS(
            sourceType,
            sourceServer,
            sourceInstance,
            sourcePort,
            sourceDatabase,
            sourceSchema,
            sourceTable,
            refreshType,
            appendColumnName,
            appendColumnMax,
            gpConn,
            queueId);
      } else if (argsCount == 4) {
        location = 3200;
        executeExt(gpConn, connectionId, selectSQL);
      }

      location = 4000;
      gpConn.close();
    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    } finally {
      if (gpConn != null) gpConn.close();
    }
  }
Example #12
0
  private static void executeExt(Connection gpConn, int connectionId, String selectSQL)
      throws Exception {
    String method = "executeExt";
    int location = 1000;

    String sourceType = "";
    String sourceServer = "";
    String sourceInstance = "";
    int sourcePort = 0;
    String sourceDatabase = "";
    String sourceUser = "";
    String sourcePass = "";
    String strSQL = "";
    Connection conn = null;
    int fetchSize = 10;

    try {
      location = 3000;

      ResultSet rs;
      Statement stmt;

      location = 3010;
      strSQL = GP.getExtConnectionDetails(gpConn, connectionId);

      location = 3020;
      stmt = gpConn.createStatement();

      location = 3030;
      rs = stmt.executeQuery(strSQL);

      while (rs.next()) {
        sourceType = rs.getString(1);
        sourceServer = rs.getString(2);
        sourceInstance = rs.getString(3);
        sourcePort = rs.getInt(4);
        sourceDatabase = rs.getString(5);
        sourceUser = rs.getString(6);
        sourcePass = rs.getString(7);
      }

      location = 3090;
      if (sourceType.equals("sqlserver")) {
        location = 3100;
        conn = CommonDB.connectSQLServer(sourceServer, sourceInstance, sourceUser, sourcePass);

        location = 3300;
        // execute the SQL Statement
        CommonDB.outputData(conn, selectSQL);

        location = 3400;
        conn.close();

      } else if (sourceType.equals("oracle")) {
        location = 4000;
        fetchSize = Integer.parseInt(GP.getVariable(gpConn, "oFetchSize"));

        location = 4100;
        conn =
            CommonDB.connectOracle(
                sourceServer, sourceDatabase, sourcePort, sourceUser, sourcePass, fetchSize);

        location = 4200;
        // execute the SQL Statement
        CommonDB.outputData(conn, selectSQL);

        location = 4400;
        conn.close();
      }

    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    } finally {
      if (conn != null) conn.close();
    }
  }
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    HttpSession session = request.getSession(true);

    try {
      Object accountObject = session.getValue(ACCOUNT);

      // If no account object was put in the session, or
      // if one exists but it is not a hashtable, then
      // redirect the user to the original login page

      if (accountObject == null)
        throw new RuntimeException("You need to log in to use this service!");

      if (!(accountObject instanceof Hashtable))
        throw new RuntimeException("You need to log in to use this service!");

      Hashtable account = (Hashtable) accountObject;

      String userName = (String) account.get("name");

      //////////////////////////////////////////////
      // Display Messages for the user who logged in
      //////////////////////////////////////////////

      Connection con = null;
      Statement stmt = null;
      ResultSet rs = null;

      String lookupID = request.getParameter("LookupMemberID");

      out.println("<HTML>");
      out.println("<HEAD>");
      out.println("<TITLE>Searching for member: lookupID</TITLE>");
      out.println("</HEAD>");
      out.println("<BODY BGCOLOR='#EFEFEF'>");
      out.println("<H3><u>Searching for Member ID: " + lookupID + "</u></H3>");
      out.println("<CENTER>");

      try {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        con =
            DriverManager.getConnection(
                "jdbc:mysql://localhost/contacts?user=kareena&password=kapoor");

        stmt = con.createStatement();
        rs =
            stmt.executeQuery(
                "SELECT * FROM userstable WHERE UserID=" + Integer.parseInt(lookupID));

        out.println("<TABLE BGCOLOR='#EFEFFF' CELLPADDING='2' CELLSPACING='4' BORDER='1'>");
        out.println("<TR BGCOLOR='#D6DFFF'>");
        out.println("<TD ALIGN='center'><B>Picture</B></TD>");
        out.println("<TD ALIGN='center'><B>User Name</B></TD>");
        out.println("<TD ALIGN='center'><B>Gender</B></TD>");
        out.println("<TD ALIGN='center'><B>City / State</B></TD>");
        out.println("<TD ALIGN='center'><B>Country</B></TD>");
        out.println("<TD ALIGN='center'><B>About User</B></TD>");
        out.println("<TD ALIGN='center'><B>User Profile</B></TD>");
        out.println("<TD ALIGN='center'><B>Add to Contact List</B></TD>");
        out.println("</TR>");

        int i = 0;
        String formName = "form";
        String buttonName = "button";

        while (rs.next()) {
          String picture = rs.getString("FileLocation");
          String user = rs.getString("UserName");
          String city = rs.getString("City");
          String state = rs.getString("State");
          String country = rs.getString("Country");
          String aboutUser = rs.getString("AboutMe1");
          String gender = rs.getString("Gender");

          formName += i;
          buttonName += i;

          out.println("<form name='" + formName + "' method='post' action='addContact'>");
          out.println("<TR>");
          out.println("<TD><img src='" + picture + "'</TD>");
          out.println("<TD>" + user + "</TD>");
          out.println("<TD>" + gender + "</TD>");
          out.println("<TD>" + city + " / " + state + "</TD>");
          out.println("<TD>" + country + "</TD>");

          out.println("<TD>" + aboutUser + "</TD>");
          out.println(
              "<TD><A href='details.jsp?type=1&data="
                  + lookupID
                  + "'><IMG SRC='images/detail.jpg'></A></TD>");
          out.println(
              "<TD><input type='submit' value='Add to Contact List' name='"
                  + buttonName
                  + "'></TD>");
          out.println("<input type='hidden' value='" + user + "' name='hiddenUser'>");
          out.println("</TR>");
          out.println("</form>");

          i++;
        }
        out.println("</TABLE>");
      } catch (Exception e) {
        out.println("Could not connect to the users database.<P>");
        out.println("The error message was");
        out.println("<PRE>");
        out.println(e.getMessage());
        out.println("</PRE>");
      } finally {
        if (rs != null) {
          try {
            rs.close();
          } catch (SQLException ignore) {
          }
        }
        if (stmt != null) {
          try {
            stmt.close();
          } catch (SQLException ignore) {
          }
        }
        if (con != null) {
          try {
            con.close();
          } catch (SQLException ignore) {
          }
        }
      }

      out.println("</CENTER>");
      out.println("</BODY>");
      out.println("</HTML>");

    } catch (RuntimeException e) {
      out.println("<script language=\"javascript\">");
      out.println("alert(\"You need to log in to use this service!\");");
      out.println("</script>");

      out.println("<a href='index.html'>Click Here</a> to go to the main page.<br><br>");

      out.println(
          "Or Click on the button to exit<FORM><INPUT onClick=\"javascipt:window.close()\" TYPE=\"BUTTON\" VALUE=\"Close Browser\" TITLE=\"Click here to close window\" NAME=\"CloseWindow\" STYLE=\"font-family:Verdana, Arial, Helvetica; font-size:smaller; font-weight:bold\"></FORM>");

      log(e.getMessage());
      return;
    }
  }