package ZubeCo; // ********************************* // * Copyright 2004, ZubeCo * // * all rights reserved * // ********************************* import java.sql.*; import java.util.*; import java.io.*; public class CreateBean { // ******************************** // * Declare the Bean Variables * // ******************************** private String driver = "COM.cloudscape.core.JDBCDriver"; private String url = "jdbc:cloudscape:ProjectDb"; private Connection conn = null; private ResultSet rs = null; private Statement stmt = null; private String number = null; private String desc = null; private String type = null; private String duration = null; private String compensation = null; private String location = null; private String skills = null; private String duties = null; private String client = null; private String contact = null; private String tele = null; private String salesman = null; private String newnum = null; private boolean found = true; // *************************** // * CreateBean constructor * // *************************** public CreateBean() { // **************************************** // * Define and connect to the database * // **************************************** try { System.setProperty("cloudscape.system.home", "C:/Program Files/Apache Tomcat 4.0/webapps/examples/Maverick"); Class.forName(driver); conn = DriverManager.getConnection(url); stmt = conn.createStatement(); } catch(Exception exc) { System.out.println("Constructor exception occurs... " + exc.getMessage() ); } } // ********************************************** // * Shutdown the connection upon termination * // ********************************************** protected void finalize() { try { rs.close(); stmt.close(); conn.close(); // Cloudscape only DriverManager.getConnection("jdbc:cloudscape:;shutdown=true"); } catch(Exception exc) { System.out.println(exc.getMessage() ); } } // *************************** // * List all D/B Elements * // *************************** public String getList() { StringBuffer sb = new StringBuffer(); try { rs = stmt.executeQuery("SELECT * FROM Project ORDER BY control_number"); while(rs.next()) { sb.append("\n"); sb.append("" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "\n"); sb.append("
Project Number" + rs.getString(1) + "
Project Description" + rs.getString(2) + "
Project Type" + rs.getString(3) + "
Project Duration" + rs.getString(4) + "
Project Compensation" + rs.getString(5) + "
Project Location" + rs.getString(6) + "
Project Skills" + rs.getString(7) + "
Project Duties" + rs.getString(8) + "
Client" + rs.getString(9) + "
Client Contact" + rs.getString(10) + "
Client Telephone" + rs.getString(11) + "
Sales Rep" + rs.getString(12) + "


\n"); } } catch(SQLException sql) { System.out.println("SQL exception has occured... " + sql.getMessage()); } catch(Exception exc) { System.out.println("General exception has occured... " + exc.getMessage()); } return sb.toString(); } // *************************** // * Insert a D/B row * // *************************** public void Insert() { try { stmt.executeUpdate("insert into Project values('" + number + "','" + desc + "','" + type + "','" + duration + "','" + compensation + "','" + location + "','" + skills + "','" + duties + "','" + client + "','" + contact + "','" + tele + "','" + salesman + "')"); } catch(SQLException sql) { found = false; System.out.println("Insert SQL exception has occured... " + sql.getMessage()); } catch(Exception exc) { System.out.println("Insert General exception has occured... " + exc.getMessage()); } } // *************************** // * Delete a D/B row * // *************************** public void Delete() { try { stmt.executeUpdate("delete from Project where control_number = '" + number + "'"); } catch(SQLException sql) { found = false; System.out.println("Delete SQL exception has occured... " + sql.getMessage()); } catch(Exception exc) { System.out.println("Delete General exception has occured... " + exc.getMessage()); } } // ********************************************** // * Generate HTML Web Page from database * // ********************************************** public void WebPage() throws Exception { PrintWriter log = new PrintWriter(new FileWriter("C://temp/jobs.htm")); try { log.println("\r"); log.println("\r"); log.println("Maverick Direct, Inc. Opportunities Page\r"); log.println("\r"); log.println("
\r"); StringBuffer sb = new StringBuffer(); try { rs = stmt.executeQuery("SELECT * FROM Project ORDER BY control_number"); while(rs.next()) { log.println("\n"); log.println("" + "" + "" + "" + "" + "" + "" + "\n"); log.println("
\n"); log.println("
Control Number" + rs.getString(1) + "
Description" + rs.getString(2) + "
Type" + rs.getString(3) + "
Duration" + rs.getString(4) + "
Compensation" + rs.getString(5) + "
Location" + rs.getString(6) + "
Skills" + rs.getString(7) + "
Duties" + rs.getString(8) + "
Email and attach your resume in Word format
Send Email


\n"); } } catch(SQLException sql) { found = false; System.out.println("SQL exception has occured... " + sql.getMessage()); } log.println("
\r"); log.println("\r"); found = true; } catch(Exception exc) { found = false; System.out.println("WebPage General exception has occured... " + exc.getMessage()); } log.close(); } // *************************** // * Modify a D/B row * // *************************** public void Modify() { try { stmt.executeUpdate("update Project set project_desc = '" + desc + "', project_type = '" + type + "', project_duration = '" + duration + "', project_compensation = '" + compensation + "', project_location = '" + location + "', project_skills = '" + skills + "', project_duties ='" + duties + "', project_client = '" + client + "', project_client_phone = '" + contact + "', project_client_contact = '" + tele + "', project_salesman = '" + salesman + "' where control_number = '" + number + "'"); } catch(SQLException sql) { System.out.println("Modify SQL exception has occured... " + sql.getMessage()); } catch(Exception exc) { System.out.println("Modify General exception has occured... " + exc.getMessage()); } } // ********************************************************************** // * Check to see if Project Number is already on Database * // ********************************************************************** public void Find() { try { rs = stmt.executeQuery("select * from Project where control_number = '" + number + "'"); boolean foundItem = rs.next(); if(!foundItem) { found = false; } } catch(SQLException sql) { System.out.println("SQL exception has occured... " + sql.getMessage()); } catch(Exception exc) { System.out.println("General exception has occured... " + exc.getMessage()); } } // ************************************* // * save the project number field * // ************************************* public void setNumber(String fld) { number = fld; } // **************************************** // * save the project description field * // **************************************** public void setDesc(String fld1) { desc = fld1; } // ********************************* // * save the project type field * // ********************************* public void setType(String fld2) { type = fld2; } // ************************************* // * save the project duration field * // ************************************* public void setDuration(String fld3) { duration = fld3; } // ***************************************** // * save the project compensation field * // ***************************************** public void setCompensation(String fld4) { compensation = fld4; } // ************************************* // * save the project location field * // ************************************* public void setLocation(String fld5) { location = fld5; } // *********************************** // * save the project skills field * // *********************************** public void setSkills(String fld6) { skills = fld6; } // *********************************** // * save the project duties field * // *********************************** public void setDuties(String fld7) { duties = fld7; } // *********************************** // * save the project client field * // *********************************** public void setClient(String fld8) { client = fld8; } // *********************************** // * save the project contact field * // *********************************** public void setContact(String fld9) { contact = fld9; } // *********************************** // * save the project tele field * // *********************************** public void setTele(String fld10) { tele = fld10; } // *************************************** // * save the project salesman field * // *************************************** public void setSalesman(String fld11) { salesman = fld11; } // ****************************************** // * return the name and phone number * // ****************************************** public String getNameNumber() { return "Insert function successful for " + number + " " + desc + ""; } // ****************************************** // * return the result of find * // ****************************************** public String getResult() { if(found) { return "This function was successful"; } else { found = true; return "This function was NOT successful

Probable cause is a DUPLICATE Project Number....." + " " + number; } } // ****************************************************** // * return the result of webpage generate * // ****************************************************** public String getWebResult() { if(found) { return "The webpage has been successfully created, ready for FTP"; } else { found = true; return "The webpage creation has failed...."; } } // ****************************************** // * return the result of delete * // ****************************************** public String getDelete() { if(found) { return "This function was successful for Project Number: " + number; } else { found = true; return "This function was NOT successful

Probable cause is an INVALID Project Number....." + " " + number; } } // ****************************************** // * set up the Modify screen * // ****************************************** public String getModify() { if(found) { StringBuffer sb = new StringBuffer(); try { rs = stmt.executeQuery("SELECT * FROM Project where control_number = '" + number + "'"); while(rs.next()) { sb.append("
\n"); sb.append("\n"); sb.append("" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "\n"); sb.append("
Project Number" + rs.getString(1) + "
Project Description
Project Type
Project Duration
Compensation
Project Location
Project Skills
Project Duties
Client
Client Contact
Client Telephon
Sales Rep

\n"); sb.append("

\n"); sb.append("


\n"); } } catch(SQLException sql) { System.out.println("SQL exception has occured... " + sql.getMessage()); } catch(Exception exc) { System.out.println("General exception has occured... " + exc.getMessage()); } return sb.toString(); } else { found = true; return "This function was NOT successful

Probable cause is an INVALID Project Number....." + " " + number; } } }