How does JSP save the last logon time of a user?

Source: Internet
Author: User

The Code is based on the access (favorite of a small website) library, for example, the date object uses java. SQL. date () type, Because java. util. date type is not allowed to be added to the DateTime type field: Author: tao

Source: http://www.tot.name

Import java. SQL .*;
Import java. text .*;

/**
* Code
*/

Public class MSaccess (favorite for small websites) DB {
Public static SimpleDateFormat sd = new SimpleDateFormat ("MMM dd yyyy ");
Private PreparedStatement pStmt = null;
Private Statement stmt = null;
Private Connection msConn = null;

Public MSaccess (favorite for small websites) DB (){
Try {
JbInit ();
Int userID = 1;
ListLoginData (); // list user information. Last Logon Time...
UpdateUserLogin (userID); // updates the information in the User table. The logon time is...
ListLoginData (); // Display User information again for comparison
}
Catch (Exception e ){
E. printStackTrace ();
}
}
Private void listLoginData () throws SQLException {
ResultSet rs1_stmt.exe cuteQuery ("select * from user_table ");
While (rs. next ()){
System. out. print (rs. getInt ("user_id") + "");
System. out. print (rs. getString ("nick_name") + "");
System. out. print (rs. getString ("last_name") + "");
System. out. print (rs. getString ("first_name") + "");
System. out. print (sd. format (rs. getDate ("last_access (favorite of small websites) _ date") + "");
}
}
Private void updateUserLogin (int userID) throws SQLException {
Java. SQL. Date today = new java. SQL. Date (System. currentTimeMillis ());
PStmt. setDate (1, today );
PStmt. setInt (2, userID );
PStmt.exe cuteUpdate ();
}
Private void jbInit () throws Exception {
Class. forName ("sun. jdbc. odbc. JdbcOdbcDriver ");
MsConn = DriverManager. getConnection ("jdbc: odbc: test_db ;;;");
String psStr = "update user_table set last_access (favorite of small websites) _ date =? Where user_id =? ";
PStmt = msConn. prepareStatement (psStr );
Stmt = msConn. createStatement ();
}

Public static void main (String [] args ){
MSaccess (favorite of small websites) DB mdb = new MSaccess (favorite of small websites) DB ();
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.