mysql比较两个时间戳并使用触发器更新下一列

时间:2016-06-09 16:28:19

标签: mysql

我在mysql表下面,

            package ex;

            import java.awt.*;
            import java.awt.event.*;
            import javax.swing.*;
            import javax.swing.table.*;
            import javax.swing.tree.*;
            import java.io.*;
            import javax.swing.event.*;

            import java.util.*;

            import java.text.*;

            class FView {
               private ATable at = new ATable();
               private JTable jt = new JTable(at);

               private JPanel pMain = new JPanel(new BorderLayout());
               private JScrollPane pCenter = new JScrollPane(jt);

               private File file;
               private File list[];
               private long size = 0, time = 0;

               FView(String str, String searchKey) {
                  init();
                  if (searchKey!=null){
                      search(str, searchKey);
                  }
                  start(str);

               }

               void init() {
                  pMain.add(pCenter, "Center");
               }

               void start(String strPath) {
                  file = new File(strPath);
                  list = file.listFiles();
                  at.setValueArr(list.length);
                  for (int i = 0; i < list.length; ++i) {
                     size = list[i].length();
                     time = list[i].lastModified();
                     for (int j = 0; j < 4; ++j) {
                        switch (j) {
                        case 0:
                           at.setValueAt(list[i].getName(), i, j);
                           break;
                        case 1:
                           if (list[i].isFile())
                              at.setValueAt(Long.toString((long) Math.round(size / 1024.0)) + "Kb", i, j);
                           break;
                        case 2:
                           if (list[i].isFile()) {
                              at.setValueAt(getLastName(list[i].getName()), i, j);
                           } else
                              at.setValueAt("파일폴더", i, j);
                           break;
                        case 3:
                           at.setValueAt(getFormatString(time), i, j);
                           break;
                        }
                     }
                  }
                  jt.repaint();
                  pCenter.setVisible(false);
                  pCenter.setVisible(true);
               }

               void search(String strPath, String searchKey){
                   file = new File(strPath);
                      list = file.listFiles();
                      at.setValueArr(list.length);
                      for (int i = 0; i < list.length; ++i) {
                         size = list[i].length();
                         time = list[i].lastModified();
                         for (int j = 0; j < 4; ++j) {
                            switch (j) {
                            case 0:
                               at.setValueAt("zzzzzzzzz", i, j);
                               break;
                            case 1:
                               if (list[i].isFile())
                                  at.setValueAt(Long.toString((long) Math.round(size / 1024.0)) + "Kb", i, j);
                               break;
                            case 2:
                               if (list[i].isFile()) {
                                  at.setValueAt(getLastName(list[i].getName()), i, j);
                               } else
                                  at.setValueAt("File Folder", i, j);
                               break;
                            case 3:
                               at.setValueAt(getFormatString(time), i, j);
                               break;
                            }
                         }
                      }
                      jt.repaint();
                      pCenter.setVisible(false);
                      pCenter.setVisible(true);
                   }

               String getLastName(String name) {
                  int pos = name.lastIndexOf(".");
                  String result = name.substring(pos + 1, name.length());
                  return result;
               }

               String getFormatString(long time) {
                  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
                  Date d = new Date(time);
                  String temp = sdf.format(d);
                  return temp;
               }

               JPanel getTablePanel() {
                  return pMain;
               }
            }

我想通过在发生e_time列更新时减去(e_time - s_time)来自动更新t_time列。

使用+----------+---------------------+---------------------+----------------+ | id | s_time | e_time | t_time | +----------+---------------------+---------------------+----------------+ | 1 | 2016-06-08 09:29:40 | 2016-06-08 09:12:47 | 00:00:00 | +----------+---------------------+---------------------+----------------+ 能够获得差异但不确定如何在e_time更新发生时自动进行此更新。

0 个答案:

没有答案