5 Replies Latest reply: Oct 12, 2006 7:19 AM by 807607 RSS

    Problem with Login Control and Database Connection , please help

    807607
      I am doing a school assignment of login and search, but i am not sure whats the error in my code. here is the code for my LoginControl and the database connection,i know i am missing something,but i just dun know what i miss... thx for help

      //Login Control

      import javax.swing.*;

      public class LoginControl
      {
      private LoginUI ui;
      protected int state;

      private SearchControl ec;

      public static final int AWAITING_LOGIN = 1;
      public static final int AWAITING_RETRIVE_PASSWORD = 2;
      public static final int FINISHED = 3;

      public LoginControl()
      {
                state = AWAITING_LOGIN;
           }

           public void setUI(LoginUI ui)
           {
                this.ui = ui;
           }

           public void setEC(SearchControl ec)
           {
                this.ec = ec;
           }

           public void checkLogin(String membershipid, String password)
           {
                if (state == AWAITING_LOGIN)
                {
                     state = AWAITING_RETRIVE_PASSWORD;
                     try
                     {
                          Member memberDB = new Member

                          if (member == null)
                          {
                               ui.displayFailMessage();
                               state = AWAITING_LOGIN;
                               return;
                          }
                          if (password.equals(member.getPassword()))
                          {
                               ui.displayOKMessage();
                               ec.loginOK(members);
                               state = FINISHED;
                          }
                          else
                          {
                               ui.displayFailMessage();
                               state = AWAITING_LOGIN;
                          }
                     }
                     catch(Exception e)
                     {
                          e.printStackTrace();
                     }
                }
                else if (state == FINISHED)
                {
                     ui.displayAlreadyLoginMessage();
                }
           }
      }

      // Database Connection

      import java.sql.*;
      import java.util.*;
      public class ConnectDatabase
      {
           public static void main(String abc[])
           {

      String cs = "jdbc:oracle:thin:@255.255.255.255:1000:a123stud";
      // ------------------------------------------------------------------------------------
      // String cs = "jdbc:oracle:thin:@255.255.255.255:1000:a123stud";
      // ------------------------------------------------------------------------------------

           String user = "123456";
           String pass = "123456";
           try
           {
                     Class.forName("oracle.jdbc.driver.OracleDriver");
                     
                     //Connection conn = DriverManager.getConnection("jdbc:odbc:myOracle");
                     Connection conn = DriverManager.getConnection(cs,user,pass);

                     Statement stmt = conn.createStatement();
                     String query = "SELECT * FROM members";
                     ResultSet rs = stmt.executeQuery(query);

                // ResultSet rs = stmt.executeQuery("SELECT * FROM members WHERE member_id = 'M0001'");
                     while(rs.next())
                     {
                          String s = rs.getString("member_id");
                          System.out.println("\n Member ID. : " + s);
                     }
                     System.out.println("\nOracle at 255.255.255.255 is working!");
                }
                catch(SQLException e)
                {
                     System.out.println("\n\nException Occured " +
                               "(Incorrect IP address, Server may be down, or SQL Exception)");
                     e.printStackTrace();
                }
                catch(ClassNotFoundException e)
                {
                     System.out.println("\n\nException Occured (CLASSNOTFOUND Exception)");
                }
           }
      }

      Message was edited by:
      styrofoam
        • 1. Re: Problem with Login Control and Database Connection , please help
          masijade
          Well, what is the error, and the stacktrace. And please post your code again, this time using code tags.

          We can't play compiler and JVM and try to analyse your code in that manner to try and find the problem. Error messages exist to point you at least in the right direction to find a correction (at least in Java when exceptions are caught and logged correctly).
          • 2. Re: Problem with Login Control and Database Connection , please help
            807607
            sorry,i am new to this forum, here is the code i found out that might be the error
            public void checkLogin(String membershipid, String password)
                 {
                      if (state == AWAITING_LOGIN)
                      {
                           state = AWAITING_RETRIVE_PASSWORD;
                           try
                           {
                                Member memberDB = new Member;
            
                                if (member == null)
                                {
                                     ui.displayFailMessage();
                                     state = AWAITING_LOGIN;
                                     return;
                                }
                                if (password.equals(member.getPassword()))
                                {
                                     ui.displayOKMessage();
                                     ec.loginOK(members);
                                     state = FINISHED;
                                }
                                else
                                {
                                     ui.displayFailMessage();
                                     state = AWAITING_LOGIN;
                                }
                           }
                           catch(Exception e)
                           {
                                e.printStackTrace();
                           }
                      }
                      else if (state == FINISHED)
                      {
                           ui.displayAlreadyLoginMessage();
                      }
                 }
            i know i am missing some statement after the Member memberDB = new Member;
            • 3. Re: Problem with Login Control and Database Connection , please help
              807607
              And here is the code for the database connection
              import java.sql.*;
              import java.util.*;
              public class TryConnect_10g
              {
                      public static void main(String abc[])
                      {
              
                  String cs = "jdbc:oracle:thin:@255.255.255.255:1234:a000studs";
              // ------------------------------------------------------------------------------------
              
              //    String cs = "jdbc:oracle:thin:@255.255.255.255:1234:a000studs";
              // ------------------------------------------------------------------------------------
              
                       String user = "123456";
                       String pass = "123456";
                       try
                       {
                             Class.forName("oracle.jdbc.driver.OracleDriver");
                             
                             //Connection conn = DriverManager.getConnection("jdbc:odbc:myOracle");
                             Connection conn = DriverManager.getConnection(cs,user,pass);
              
                             Statement stmt = conn.createStatement();
                             String query = "SELECT * FROM members";
                             ResultSet rs = stmt.executeQuery(query);
              
                           // ResultSet rs = stmt.executeQuery("SELECT * FROM members WHERE member_id = 'M0001'");
                             while(rs.next())
                             {
                                   String s = rs.getString("member_id");
                                   System.out.println("\n Member ID. : " + s);
                             }
                             System.out.println("\nOracle10g at 255.255.255.255  is working!");
                        }
                        catch(SQLException e)
                        {
                             System.out.println("\n\nException Occured " +
                                       "(Incorrect IP address, Server may be down, or SQL Exception)");
                             e.printStackTrace();
                        }
                        catch(ClassNotFoundException e)
                        {
                             System.out.println("\n\nException Occured (CLASSNOTFOUND Exception)");
                        }
                      }
              }
              • 4. Re: Problem with Login Control and Database Connection , please help
                807607
                Hai,
                Tell the specfic errors or problems you are meeting with.
                rgds,
                rDrose
                • 5. Re: Problem with Login Control and Database Connection , please help
                  807607
                  Well, for a start you need a parameter list for a new, even if there are no parameter you need ().

                  And you seems to be setting the memberDB variable, but then looking at one called simply member.