以下是我的程序中的示例代码,它查询数据库并将结果复制到目录中的不同文件中。我想要实现的是以下代码应该以 15 分钟的间隔运行,以便使用新数据更新文件。
public class CountryLogtoCSV {
static Connection con = null;
static ResultSet rs = null;
public static void main(String... argv)
{
FileWriter filewriter=null;
File countryHits=new File("countryhits.csv");
filewriter=new FileWriter(countryHits);
query = "SELECT countryID, count(*) as total FROM mobileCountryLog"
+ " WHERE aHitType='ALL' AND aDate>'2012-11-06' GROUP BY countryID";
rs = Database.getResult(connection,query)
while (rs.next()) {
//Writing result to File, FileWriter is used
filewriter.append(rs.getString("countryID"));
filewriter.append(rs.getString("total"));
filewriter.flush();
}
File countryUnique=new File("countryunique.csv");
filewriter=new FileWriter(countryUnique);
query = "SELECT countryID, count(*) as total FROM mobileCountryLog"
+ " WHERE (aHitType='UNIQUE'AND aDate>'2012-11-06' GROUP BY countryID;
rs = Database.getResult(connection,query)
while (rs.next()) {
//Writing Result to File, FileWriter is used
filewriter.append(rs.getString("countryID"));
filewriter.append(rs.getString("total"));
filewriter.flush();
}
rs.close();
}
}
如何每 15 分钟运行一次这个 java 类?
谢谢,