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