How the JSP saves the user's last logon time

Source: Internet
Author: User
Tags date odbc sql string stmt
Js

The code is the Java.sql.Date () type used by the Date object in the Access library as an example, because the test java.util.Date type cannot be added to a field of datetime type:

Import java.sql.*;
Import java.text.*;

/**
* Code
*/

public class Msaccessdb {
public static SimpleDateFormat sd=new SimpleDateFormat ("MMM dd yyyy");
Private PreparedStatement Pstmt=null;
Private Statement Stmt=null;
Private Connection Msconn=null;

Public Msaccessdb () {
try {
Jbinit ();
int userid=1;
Listlogindata ();//list user information, last logon time ...
Updateuserlogin (UserID)//update the information in the user table, logon time ...
Listlogindata ()//display user information again in order to compare
}
catch (Exception e) {
E.printstacktrace ();
}
}
private void Listlogindata () throws SQLException {
ResultSet rs=stmt.executequery ("SELECT * from user_table");
while (Rs.next ()) {
System.out.print (Rs.getint ("user_id") + "T");
System.out.print (rs.getstring ("nick_name") + "T");
System.out.print (rs.getstring ("last_name") + "T");
System.out.print (rs.getstring ("first_name") + "T");
System.out.print (Sd.format (Rs.getdate ("Last_access_date")) + "\ n");
}
}
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.executeupdate ();
}
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_date=?" where user_id=? ";
Pstmt=msconn.preparestatement (PSSTR);
Stmt=msconn.createstatement ();
}

public static void Main (string[] args) {
Msaccessdb mdb=new Msaccessdb ();
}
}

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.