Solved

What is wrong??????

Posted on 1998-02-25
7
281 Views
Last Modified: 2012-08-13
Can someone tell me why this code does not write my MS Access located on a webserver??  What is supposed to happen is.....when the user visits a web site he/she is to fill out this form, the info is then suppose to go to a MS Access database located on my web server.

Thanks in advance

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.sql.*;

public class FormRequest extends Applet {

      Button open;
      DisplayFrame f;

    /**
     * Initializes the applet.  You never need to call this directly; it is
     * called automatically by the system once the applet is created.
     */
    public void init() {
   
      open = new Button("Open the Frame");
      add(open);
    }
   
    public boolean action(Event e, Object o){
   
      if(e.target == open) {
          String s = "Reprint Request Form";
          f = new DisplayFrame(s);
          f.resize(300, 450);
          f.show();
      }
      return true;
    }
   
class DisplayFrame extends Frame{

      TextField reqName;
      TextField reqEmail;
      TextField reqICD;
      TextField reqMailAdd;
      TextField reqCountry;
      TextField reqCity;
      TextField reqState;
      TextField reqZip;
      TextField reqArticle;
      TextField reqJournal;
      
      Label lb1, lb2, lb3, lb4, lb5, lb6, lb7, lb8, lb9, lb10;
      Button submit, clear;
      
    public DisplayFrame(String s){
   
      super(s);
      submit = new Button("Submit Request");
      clear = new Button("Clear Form");
      setLayout(new FlowLayout(FlowLayout.LEFT));
      
          lb1 = new Label("Name:");
          reqName = new TextField(20);
          add(lb1);
          add(reqName);
          lb2 = new Label("Email Address:");
          reqEmail = new TextField(20);
          add(lb2);
          add(reqEmail);
          lb3 = new Label("Organization or Institution:");
          reqICD = new TextField(20);
          add(lb3);
          add(reqICD);
          lb4 = new Label("Mailing Address:");
          reqMailAdd = new TextField(20);
          add(lb4);
          add(reqMailAdd);
          lb5 = new Label("Country:");
          reqCountry = new TextField(10);
          add(lb5);
          add(reqCountry);
          lb6 = new Label("City:");
          reqCity = new TextField(15);
          add(lb6);
          add(reqCity);
          lb7 = new Label("State:");
          reqState = new TextField(5);
          add(lb7);
          add(reqState);
          lb8 = new Label("Zip Code:");
          reqZip = new TextField(9);
          add(lb8);
          add(reqZip);
          lb9 = new Label("Title of Article you are requesting:");
          reqArticle = new TextField(30);
          add(lb9);
          add(reqArticle);
          lb10 = new Label("Journal Published in:");
          reqJournal= new TextField(30);
          add(lb10);
          add(reqJournal);
          add(submit);
          add(clear);
    }
   
    public boolean action(Event evt, Object obj){
   
      if(evt.target == submit) {
          hide();
          dispose();
      return true;
      }
    return super.handleEvent(evt);
    }

    public boolean handleEvent(Event e){
   
      if(e.id == Event.WINDOW_DESTROY){
          f.hide();
          f.dispose();
      return true;
      }
      return super.handleEvent(e);
    }
   
     private synchronized void processRequest() {
   
      String stringName, stringEmail, stringICD, stringMailAdd, stringCountry, stringCity,
            stringState, stringZip, stringArticle, stringJournal;
      
      try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          String url = "jdbc:odbc:RequestData";
          Connection con = DriverManager.getConnection(url, "", "");
          Statement stmt = con.createStatement();
          
          stringName = reqName.getText();
          stringEmail = reqEmail.getText();
          stringICD = reqICD.getText();
          stringMailAdd = reqMailAdd.getText();
          stringCountry = reqCountry.getText();
          stringCity = reqCity.getText();
          stringState = reqState.getText();
          stringZip = reqZip.getText();
          stringArticle = reqArticle.getText();
          stringJournal = reqJournal.getText();
          
          String updatestring = "INSERT INTO req_info(reqName, reqEmail, reqICD," +
                      "reqMailAdd, reqCountry, reqCity, reqState, reqZip, reqArticle, reqJournal)"
                          + "VALUES(" + stringName + ", '" + stringEmail + "', '" + stringICD +
                    "', '" + stringMailAdd + "', '" + stringCountry + "', '" + stringCity +
                    "', '" + stringState + "', '" + stringZip + "', '" + stringArticle +
                    "', '" + stringJournal + "')";
                          int ct = stmt.executeUpdate(updatestring);
                          stmt.close();
                          }
                          catch(Exception e){}
                          }

                      }
    /**
     * Called to start the applet.  You never need to call this directly; it
     * is called when the applet's document is visited.
     */
    public void start() {
    }

    /**
     * Called to stop the applet.  This is called when the applet's document is
     * no longer on the screen.  It is guaranteed to be called before destroy()
     * is called.  You never need to call this method directly
     */
    public void stop() {
    }

    /**
     * Cleans up whatever resources are being held.  If the applet is active
     * it is stopped.
     */
    public void destroy() {
    }
}

0
Comment
Question by:Maurice072297
  • 4
  • 3
7 Comments
 

Expert Comment

by:kaleemaziz
ID: 1233254
Where are you calling processRequest()?
For something as simple as that, you are taking too many pains. You are the best judge, by why 1.0? Here is a sample from 1.1. Work on these lines, you will benefit. (If you think I have given an unasked advice, you may give me a '0', but I'd not mind. I replied because I knew the solution. I am not in the rat race for points!)
Regards.
------------------
/*
 * This sample applet just selects 'Hello World' and the date from the database
 */

// Import the JDBC classes
import java.sql.*;

// Import the java classes used in applets
import java.awt.*;
import java.io.*;
import java.util.*;

public class JdbcApplet extends java.applet.Applet
{
  // The driver to load
  static final String driver_class = "oracle.jdbc.driver.OracleDriver";

  // The connect string
  static final String connect_string =
                  "jdbc:oracle:thin:scott/tiger@dlsun511:1721:dbms733";

  // This is the kind of string you woudl use if going through the
  // Oracle 8 connection manager which lets you run the database on a
  // different host than the Web Server.  See the on-line documentation
  // for more information.
  // static final String connect_string = "jdbc:oracle:thin:scott/tiger@(description=(address_list=(address=(protocol=tcp)(host=dlsun511)(port=1610))(address=(protocol=tcp)(host=pkrishna-pc2)(port=1521)))(source_route=yes)(connect_data=(sid=orcl)))";

  // The query we will execute
  static final String query = "select 'Hello JDBC: ' || sysdate from dual";
 

  // The button to push for executing the query
  Button execute_button;

  // The place where to dump the query result
  TextArea output;

  // The connection to the database
  Connection conn;

  // Create the User Interface
  public void init ()
  {
    this.setLayout (new BorderLayout ());
    Panel p = new Panel ();
    p.setLayout (new FlowLayout (FlowLayout.LEFT));
    execute_button = new Button ("Hello JDBC");
    p.add (execute_button);
    this.add ("North", p);
    output = new TextArea (10, 60);
    this.add ("Center", output);
  }

  // Do the work
  public boolean action (Event ev, Object arg)
  {
    if (ev.target == execute_button)
    {
      try
      {
      // Clear the output area
      output.setText (null);

      // See if we need to open the connection to the database
      if (conn == null)
      {
        // Load the JDBC driver
        output.appendText ("Loading JDBC driver " + driver_class + "\n");
        Class.forName (driver_class);

        // Connect to the databse
        output.appendText ("Connecting to " + connect_string + "\n");
        conn = DriverManager.getConnection (connect_string);
        output.appendText ("Connected\n");
      }

      // Create a statement
      Statement stmt = conn.createStatement ();

      // Execute the query
      output.appendText ("Executing query " + query + "\n");
      ResultSet rset = stmt.executeQuery (query);

      // Dump the result
      while (rset.next ())
        output.appendText (rset.getString (1) + "\n");

      // We're done
      output.appendText ("done.\n");
      }
      catch (Exception e)
      {
      // Oops
      output.appendText (e.getMessage () + "\n");
      }
      return true;
    }
    else
      return false;
  }
}

0
 

Author Comment

by:Maurice072297
ID: 1233255
I am not gathering any info from the database....What I am trying to accomplish is sending data to a MS Access database.  What you have give me is a very acceptable answer....however right now I am just trying to figure out why the code I have is not working properly.  Also I am new to JDBC, that is why I am use 1.0 instead of 1.1 (I am learning from the bottom up.)
0
 

Accepted Solution

by:
kaleemaziz earned 50 total points
ID: 1233256
You have your answer in my earlier reply. Read again closely. The rest of the code is an attempt to show you better methods.
"Where are you calling processRequest()?" means that you should be calling processRequest() somewhere for that action to occur.
So, in your code ...
if(evt.target == submit) {
                              hide();
                              dispose();
                          return true;
                          }
you should make a call to processRequest().
if(evt.target == submit) {
                             processRequest(); // like this.
                               hide();
                              dispose();
                          return true;
                          }
How else would you expect your insertion to take place?
From your coding I very well know that you are a learner.
Also, you will have to setup your database in (32-bit) ODBC driver in your Control Panel. Have you done that, or should I send you those details as well?
Regards.
                                               Kaleem Aziz.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Maurice072297
ID: 1233257
I forgot to resubmit my code....I did realize that I had forgotten the processRequest() statement, that I fixed.  But it still did not work.  Maybe the person who set up the ODBC info on the webserver did not set it up correctly.  If you don't mind could you send me the details

Thanks
0
 

Author Comment

by:Maurice072297
ID: 1233258
By looking at the code though, it should work fine right??
0
 

Expert Comment

by:kaleemaziz
ID: 1233259
From the code, everything appears to be right.
Though I know you are learning, I could see that you have posted the older code.
The details to setup your ODBC configuration are as simple as:
1. Go to Control Panel and execute ODBC icon.
2. In Windows NT, you'll see a card stack wit 'User DSN', 'System DSN', etc.
3. Select the 'System DSN' (since you'd want your applet to work even if you logged in as another user).
4. You must be having your database 'RequestData' with the necessary fields ready?
5. Click on 'Add...' button.
6. On the 'Create New Data Source', select Microsoft Access Driver (*.mdb) and click on 'Finish'.
7. On the 'ODBC Microsoft Access 97 Setup' dialog, click on 'Select' button. This opens a file dialog with title 'Select Database'.
8. Give the path of your database file (which by default will be in your personal folders).
9. Give the Data Source Name very carefully. This is the name that you should be using in your Java program. Since I see that you call your database 'RequestData', you should give it exactly like that here. Give the same as description, for the time being, though this is not necessary. Your database file may be any name, but the data source name must match one to one with your Java database name (i.e., RequestData).
10. Try similar things on Win95, since I don't have one right now.
11. Execute your program and it should work.

Bye.
                                                        Kaleem.
10.

0
 

Author Comment

by:Maurice072297
ID: 1233260
Your help was greatly appreciated.  
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Groovy problem when using SOAPUI : DispatchException occurred 7 60
servlet example 11 49
arguments to jar 5 35
Selenium docs api java index 3 48
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question