【发布时间】:2019-07-26 16:21:39
【问题描述】:
我的 MySQL 数据库中有一个数据类型为 datetime 的列,但是当我从该列检索数据时,它显示的时间是 00:00:00,而不是我存储的时间。
public class MainWork extends TimerTask {
private static final DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); 公共无效运行(){
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =DriverManager.getConnection(
"jdbc:mysql://localhost:3306/reminder","sarthak","sar31thak");
Statement stmt=con.createStatement();
ResultSet rs= stmt.executeQuery("select * from ToDo");
while(rs.next()){
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date dt = new Date();
dt=rs.getDate(2);
String activity=rs.getString(1);
String str= sdf.format(dt);
Date localDate = new Date();
String today;
today=sdf.format(localDate);
if(str.equals(today)){
JOptionPane optionPane = new JOptionPane(activity,JOptionPane.WARNING_MESSAGE);
JDialog dialog = optionPane.createDialog("REMINDER");
//Toolkit.getDefaultToolkit().beep();
dialog.setAlwaysOnTop(true); // to show top of all other application
dialog.setVisible(true); // to visible the dialog
}
else
{
continue;
}
}
}
catch (Exception e)
{System.out.println("Got an ERROR");}
}
public static void main(String args[]){
Timer t1 = new Timer();
t1.schedule(new MainWork(), 0,60000);
}
}
【问题讨论】:
-
select *在这种情况下是相当邪恶的,因为这意味着我们不知道您选择的实际列或顺序。请在您的选择子句中明确写出所有列。这是解决问题的第一步。
标签: java mysql web-applications