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 ();
}
}