Link to home
Start Free TrialLog in
Avatar of robinad
robinad

asked on

Applets and Access Database

Could someone help me with this problem which I'm having during compile time?

Here's my program:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.sql.*;

public class SignIn extends JApplet
   implements ActionListener {

   private String userid, passwd;
   private String msg = " ";
   private JTextField id;
   private JPasswordField pass;
   private JButton login;
   private Connection conn;
   private PreparedStatement pstmt;
   private ResultSet rst;

   public void init() {
      JLabel idp = new JLabel("User ID:", JLabel.RIGHT);
      JLabel passp = new JLabel("PIN:", JLabel.RIGHT);
      id = new JTextField(9);
      pass = new JPasswordField(9);
      pass.setEchoChar('*');
      login = new JButton("Login");

      // Add user ID and password to the applet.
      add(idp);
      add(id);
      add(passp);
      add(pass);
      add(login);


     // Register to receive action events.
     id.addActionListener(this);
     pass.addActionListener(this);
     login.addActionListener(this);
   }

   // This will select ID_Number and PIN from Customer table.
   private boolean connectToDb() {
      boolean success = false;

      try
      {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        conn = DriverManager.getConnection("jdbc:odbc:angie", " ", " ");                                           success = true;
      }
      catch (ClassNotFoundException e)
      {
        e.printStackTrace();
      }
      catch (SQLException e)
      {
        e.printStackTrace();
      }
      return success;
     }  // End of connectToDb().

        public boolean validateUser()
        {
          userid = id.getText();
          passwd = pass.getText();
          boolean success = false;

          try
          {
            pstmt = conn.prepareStatement("select ID_Number, PIN from Customer where (ID_Number = 'userid' and PIN = 'passwd')");
            rst = pstmt.executeQuery();

            while (rst.next())
            {
              String dbId = rst.getString(1);
              String dbPswd = rst.getString(2);

              if(userid.equals(dbId) && passwd.equals(dbPswd))
                success = true;
            }
       }
       catch (SQLException e)
       {
         e.printStackTrace();
       }
       return success;
       }

   // User pressed Login.
   public void actionPerformed(ActionEvent ae) {
      String str = ae.getActionCommand();
         if(str.equals("Login")) {
             if (connectToDb() == true && validateUser() == true) {
               msg = "You have successfully logged in.";
             }
             else {
               msg = "You have entered an invalid User ID/PIN.";
             }
             repaint();
         }
      }

    // Prints the string to the screen.
    public void paint (Graphics g) {
       g.drawString(msg, 6, 100);
    }
}


The error which I see is:

Note: SignIn.java uses or overrides a deprecated API.
Note: Recompile with -deprecated for details.

Not sure what -deprecated means....Need help understanding and a solution to the problem. Thanking you in advance.
ASKER CERTIFIED SOLUTION
Avatar of twalgrave
twalgrave

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Recommendation: Accept Comment from Twalgrove
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

DominicCronin
EE Cleanup Volunteer