Results 1 to 2 of 2
- 03-25-2012, 04:08 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 1
- Rep Power
- 0
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()); }
- 03-26-2012, 10:49 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
Similar Threads
-
Desingn time properties missing at run time - Netbeans
By junaid in forum New To JavaReplies: 3Last Post: 12-07-2011, 07:00 AM -
Calender date discard/remove Z and time at the end of the calender date
By reach2sudhakar in forum Advanced JavaReplies: 18Last Post: 05-11-2011, 07:36 AM -
converting string (GMT date) to date in US time.
By JRuyechan in forum New To JavaReplies: 1Last Post: 10-15-2010, 07:07 AM -
How to detect first time login to the web application
By dmane in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 08-04-2010, 06:18 PM -
Single login for a user at a time
By mitali l joshi in forum Java ServletReplies: 4Last Post: 01-22-2010, 10:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks