Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Unable to authenticate!

  1. #1
    Member
    Join Date
    Apr 2011
    Location
    Niperia
    Posts
    30
    My Mood
    Amazed
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Unable to authenticate!

    Please can someone point out to me why the commented lines aren't been executed?

    public boolean managerLogin(int id, String usn, String pwd, boolean in){
    	try{
    	  try{
    		Class.forName("com.mysql.jdbc.Driver").newInstance();
    		}catch(Exception e){
    	JOptionPane.showMessageDialog(null, e.getMessage());
    	}
    java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/phoneShopSystem","aknessy", dbLogin.db());
    String query = "SELECT managerID, managerUsername, managerPwd"
    + " FROM manager WHERE managerID = ? AND"
    + " managerUsername = ? AND"
    + " managerPwd = ?";
    java.sql.PreparedStatement pst= con.prepareStatement(query,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    pst.setInt(1, id);
    pst.setString(2, usn);
    pst.setString(3, pwd);
     
    rset = pst.executeQuery();
     
    if(rset.next()){
    int i = rset.getInt(1);
    String u = rset.getString(2);
    String p = rset.getString(3);
     
    		/*From Here 	
    		  if((i == id) && (u.equals(usn)) && (p.equals(pwd))){
    			in = true;
    			new managerCorner();
    		}else{
    		in = false;
    	JOptionPane.showMessageDialog(null, "The User: "+ usn +" With ID "+ id + " \n"
    	+ "Does Not Exist!", "\nLogin Failed!", JOptionPane.OK_OPTION);
    	} To Here aren't been executed!*/			
     
    rset.close();
    	con.close();
    	}
    }catch(SQLException sql){
    JOptionPane.showMessageDialog(null, sql.getMessage(),"SQL ERROR!!!", JOptionPane.OK_OPTION);
    }
    return in;
    }


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,684
    Thanks
    25
    Thanked 333 Times in 309 Posts

    Default Re: Unable to authenticate!

    What do you mean by they are not executing?
    It is an if/else statement, so one of them HAS to execute. The only way it wouldn't execute is if the rset.next() if statement a few lines before returned false. But as long as rset.next() is true, one of them must execute.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. The Following User Says Thank You to aussiemcgr For This Useful Post:

    aknessy (October 24th, 2013)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,043
    Thanks
    52
    Thanked 2,280 Times in 2,251 Posts

    Default Re: Unable to authenticate!

    why the commented lines aren't been executed?
    Lines inside of comments are not compiled and won't be executed.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    aknessy (October 24th, 2013)

  6. #4
    Member
    Join Date
    Apr 2011
    Location
    Niperia
    Posts
    30
    My Mood
    Amazed
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Unable to authenticate!

    Thanks for your kind replies! I found the solution, was doing something wrongly.

Similar Threads

  1. how to authenticate user in swing application from twitter ?
    By varunjain0888 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 13th, 2013, 05:52 AM
  2. Unable to read '#' value using getParameter
    By napster12 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 27th, 2012, 05:06 AM
  3. Unable to view date
    By Rajiv in forum Web Frameworks
    Replies: 1
    Last Post: August 17th, 2011, 09:03 AM
  4. How to authenticate user using oracle JAZN.xml
    By rajnish.rathi in forum Member Introductions
    Replies: 1
    Last Post: June 14th, 2011, 08:19 AM
  5. Unable to create a new connection!
    By fh84 in forum JDBC & Databases
    Replies: 1
    Last Post: November 20th, 2009, 04:58 PM