Results 1 to 2 of 2
  1. #1
    masterpinuno is offline Member
    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Default HELP about login time and date in netbeans

    what code should I use to insert a time and date where in when I press login button, the log in time and date of the user will be recorded to the database of mysql automaticallly? thank you and really appreciated your help.. thank you so much..

    Java Code:
    int pat=0;     
    
    String sql = "Select * from admin";
    try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/admin","root","");
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    
    
    String user = jTextField1.getText();
    String pwd = new String (jPasswordField2.getPassword());
    
    while(rs.next()) {
        
    String uname=rs.getString("Username");
    String password=rs.getString("Password");
    
    if ((user.equals(uname)) && (pwd.equals(password))){
        new AdminLogIn().setVisible(true);
        dispose();
        
        pat++;
        }
    }
    if (pat==0) {
    JOptionPane.showMessageDialog(null, "Cannot find Username/Password in Database!");
    }
    }
        
    catch (Exception e){
    JOptionPane.showMessageDialog(this, e.getMessage());
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: HELP about login time and date in netbeans

    First off, don't check user credentials like that.
    SELECT username FROM admin WHERE username = ? AND password = ?
    Then use a PreparedStatement and bind (use setString()) to set the two variables.
    Then you either get one row back (rs.next() is true) in which case these are correct, or no rows, in which case they are wrong.

    As for your actual problem, is there a table in your database for storing the login time?
    Then insert a row.
    If it's just a last_logged_in column in the admin table then just UPDATE that value with the current time stamp.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 3
    Last Post: 12-07-2011, 07:00 AM
  2. Replies: 18
    Last Post: 05-11-2011, 07:36 AM
  3. converting string (GMT date) to date in US time.
    By JRuyechan in forum New To Java
    Replies: 1
    Last Post: 10-15-2010, 07:07 AM
  4. How to detect first time login to the web application
    By dmane in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 08-04-2010, 06:18 PM
  5. Single login for a user at a time
    By mitali l joshi in forum Java Servlet
    Replies: 4
    Last Post: 01-22-2010, 10:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •