What is wrong??????

Posted on 1998-02-25
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.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");
    public boolean action(Event e, Object o){
      if( == open) {
          String s = "Reprint Request Form";
          f = new DisplayFrame(s);
          f.resize(300, 450);
      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){
      submit = new Button("Submit Request");
      clear = new Button("Clear Form");
      setLayout(new FlowLayout(FlowLayout.LEFT));
          lb1 = new Label("Name:");
          reqName = new TextField(20);
          lb2 = new Label("Email Address:");
          reqEmail = new TextField(20);
          lb3 = new Label("Organization or Institution:");
          reqICD = new TextField(20);
          lb4 = new Label("Mailing Address:");
          reqMailAdd = new TextField(20);
          lb5 = new Label("Country:");
          reqCountry = new TextField(10);
          lb6 = new Label("City:");
          reqCity = new TextField(15);
          lb7 = new Label("State:");
          reqState = new TextField(5);
          lb8 = new Label("Zip Code:");
          reqZip = new TextField(9);
          lb9 = new Label("Title of Article you are requesting:");
          reqArticle = new TextField(30);
          lb10 = new Label("Journal Published in:");
          reqJournal= new TextField(30);
    public boolean action(Event evt, Object obj){
      if( == submit) {
      return true;
    return super.handleEvent(evt);

    public boolean handleEvent(Event e){
      if( == Event.WINDOW_DESTROY){
      return true;
      return super.handleEvent(e);
     private synchronized void processRequest() {
      String stringName, stringEmail, stringICD, stringMailAdd, stringCountry, stringCity,
            stringState, stringZip, stringArticle, stringJournal;
      try {
          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);
                          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() {

Question by:Maurice072297
  • 4
  • 3

Expert Comment

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!)
 * 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.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 =

  // 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 ( == execute_button)
      // 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 ( ())
        output.appendText (rset.getString (1) + "\n");

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


Author Comment

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.)

Accepted Solution

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( == submit) {
                          return true;
you should make a call to processRequest().
if( == submit) {
                             processRequest(); // like this.
                          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?
                                               Kaleem Aziz.
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.


Author Comment

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


Author Comment

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

Expert Comment

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.



Author Comment

ID: 1233260
Your help was greatly appreciated.  

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 36
web application structure 18 77
how to install java on RHEL image on EC2 4 27
JAVA API design with micro service cloud in mind 1 18
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

777 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