using the coding shown below i have managed to retrive data from a sql database in a server using php.
i need to check database periodically to see if any new data added and if any, i need to retrive them to my java application.
i’m using netbeans IDE
how can i do this?
try {
URL url = new URL("http://taxi.com/login.php?param=10");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
In this solution, I assume that you use at least Java 5.
Let’s say you want to check for new data every 5 minutes and terminate after 25 minutes.
You would do this :
PHPDataChecker.java
Main.java