Solved

What is wrong??????

Posted on 1998-02-25
7
272 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now