以下是我程序中的样例代码,用于查询数据库并将结果复制到目录中的不同文件中。我想要实现的是,以下代码应该每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类?
谢谢。