Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:23:51+00:00 2026-06-13T22:23:51+00:00

Following is a sample code from my program which queries the database and results

  • 0

Following is a sample code from my program which queries the database and results are copied to different files in a directory. What I want to achieve is following code should run in 15 minutes interval so that Files are updated with the new data.

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

}

}

How to run this java class in every 15 minutes??

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:23:52+00:00Added an answer on June 13, 2026 at 10:23 pm

    If you are running on Unix type OS, then you can do this with cron:

    Add this to the crontab:

    */15 * * * * /yourpath-to-jdk/bin/java -cp yourclasspath CountryLogtoCSV
    

    You can also do it in Java using the Executor package, but that means you will have to have that code running at all time or else it won’t execute. With cron, your code only needs to run every 15 minutes (or whatever you set the time to be). This means that if your server reboots or your code crashes at one time, it will try again at the next cycle. Much more stable and easier to manage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following sample code which doesn't seem to want to run. import
I have downloaded sample code from Apple Center.I also have gone through following question:
Following code is from a sample of playframework-2.0: /** * Display the dashboard. */
I have the following very simple code snippet which is loaded from a separate
The following code was been given from our school as a sample for circular
I have the following sample code and noticed that if I attempt to use
I wrote the following sample code to see how ARC works @property (nonatomic, weak)
I have a Dictionary bound to DataGridView by using following sample code. DataGridView bound
We implemented In-app Billing one year ago with no problems following the sample code
The following code sample (also at http://jsfiddle.net/MZwBS/ ) var items = []; items.push({ example:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.