How to access FTP in Java?

Java Application - Upload usage statistics to website?

  • I'm developing quite a popular java application (well, plugin, but for all intents and purposes it runs like an application) and am receiving a large number of users complaining about errors and the line which happen. Naturally, they don't know what a stack trace is or anything like that, so i've come across the idea of having a web interface where I can view each application instances running state and any errors encountered, and its worked will. I've been using FTP where the application uploads a .txt file with the basic stats every time it starts, along with any errors. HERE IS THE PROBLEM: Its gotten so popular that the FTP server has started getting over capacity (and crashing) meaning nothing gets uploaded to the error site any more, and the start up of the application is slowed by 10 seconds while the application waits for a response from a server which is never going to until it times out. HERE IS WHAT I WANT: A solution (i.e. some code and ideas) on how I can get my application to upload usage statistics to a remote server that I can view. Java doesn't want to work with SQL databases and FTP is out of reach. SQL constantly gives me issues when I try to edit it in java - from random disconnecting, to unfathomable data types to web hosts allowing no external access. I have had the idea to make a page which the application can make a POST to, which then updates the SQL database, but that (if possible) requires knowledge of PHP which I do not have. IN SHORT: If anyone knows how I can make a webpage update a SQL database when its given a POST, and read the database when its given a GET, I would be very very pleased. Thanks!

  • Answer:

    If you store a POST in a variable, you can run an update query with the value of the POST variable e.g. <?php $stats=$_POST['stats']; //Connect to MySQL mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); //Select a database to use mysql_select_db("Database_Name") or die(mysql_error()); //Run a query with the value of $stats mysql_query("INSERT INTO `statistics` VALUES ('$stats')"); ?> To get the rows in your statistics table, it would probably be better just to run a query and display the contents in an html table instead of writing to a txt file. It takes minimal bandwidth and you won't have to worry about downloading via FTP. e.g. <?php //Note you have to connect to your database first //Get data from statistics table $result = mysql_query("SELECT * FROM statistics") or die(mysql_error()); //Print contents of rows in an html table on screen echo "<table border='1'>"; echo "<tr> <th>Statistics</th> </tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo $row['stats']; echo "</td></tr>"; } echo "</table>"; ?> PHP has full OOP support so to save yourself the headache, you may want to consider developing your app with PHP. Hope this helps

RjSowden at Yahoo! Answers Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.