import java.sql.*;

/**
* DataBaseInsert.java
* Written by Morgan Catlin Email: [EMAIL PROTECTED]
*   August 19, 1999
*
* Variables:
*   String something = something to insert into the database
*
* Methods:
*   String getSomething() = returns something
*   void setSomething() = sets something
*   String connect() = connects to database returns success or failure
message
*   String insertSomething() = inserts something to the database
**/

public class DataBaseInsert {

   String something;

   public DataBaseInsert() {
      something = null;
   } // constructor DataBaseInsert

   /**
    * Accessor for something
    */
   public String getSomething() {
      return something;
   }

   /**
    * Mutator for something
    */
   public void setSomething(String asomething) {
      something = asomething;
   }

   public String connect() {
      try {
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
         return "Driver Loaded!";
      } catch (Exception E) {
         return "Unable to load driver.";
      }
   }

   public String insertSomething() {
      try {
         Connection C = DriverManager.getConnection("jdbc:odbc:MyDB", "", "");

         Statement Stmt = C.createStatement();

         String insert = "INSERT INTO AwardPerson (BrandDesc) VALUES ('" +
this.getSomething() + "')";

         int stmtInt = Stmt.executeUpdate(insert);

         Stmt.close();
         C.close();
         return "Inserted row " + stmtInt;

      } catch (SQLException E) {
                return "SQLException: " +  E.getMessage();
      } catch (Exception E) {
                return "Error " + E.toString();
      }
   }
} // class DataBaseInsert

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to