I'm designing an Android app that stores its data in xml files locally; local data are part of all data stored at a server. I need remote file path to download and view locally. user can list remote files in a listView and check files (eg.. books) to download;
What can the structure of the remote repo be? (SQL) How can I make the query and receive result? (JSON) Any way to sync (subtract existing files from remote)?
your question is too generic and wraps a big thing stuff, since you are asking the repository, the query mechanism and the sync between the server and your app.
the most common way to do this is allocating all you data in server database (mysql i.e. or xml files, last is too more complex) query it with a (php, jsp, asp.*) web service and retrieving the web service result (in your android application) using HttpURLConnection, URL classes to connect and read the ws result.
Later, the sync can be on a background thread that continously do the above operation.
maybe you can do it with the DownloadManager service, but i recommend you a little read to the documentation.
Related
I'm developing a knowledge base java application, where I can store and retrieve annotations with its title, date when the note was created (SQL datetime), content, tags about the annotation, etc.
It can be done easily with a database (I'm using SQL Server 2014), but the main problem is that the server is running on my own PC and it has to be always on and running the SQL Server. Also, I would like to extend the application by storing and retrieving this kind of data on mobile apps for Android and iOS.
Is there any other way to store that type of data in some files so it can be uploaded to some cloud storage like Dropbox ? After storing it on Dropbox, all I would have to do is sync the app with dropbox, get the files and read/write stuff.
UPDATE: Thanks for all the answers they helped me a lot. The best solution for me is to replace SQL Server with SQlite, as Gabe Sechan commented. Now I can make changes on the database without the need of a server running 24/7 and I can use the same database on Android and iOS apps.
You can use just a basic ajax call to pull content from a Dropbox "public" URL.
function(contenturl,intoselector,callback){
if (contentwindow.currenttopic!==contentID){
jQuery.ajax({
type:'GET',
url:'//www.corsproxy.com/'+contenturl,
dataType:'text',
async:true,
success:function(data){
intoselector.html(data);
if (jQuery.type(callback)==="function")
callback();
}
});
}
Notice that this example pulls through corsproxy so that you don't receive any XSS errors, so the url you pass needs to not contain a protocol itself.
If you want to pull a JSON or XML string that is stored in the file, then you might need to play around with the dataType and contenttype options in the ajax call.
This can also be done using Google spreadsheets:
Reading:
Create a spreadsheet and publish it on the web
Use one of the many available Javascript libraries for pulling data from Google spreadsheets:
http://jlord.us/sheetsee.js/ (which uses Tabletop.js)
http://chriszarate.github.io/sheetrock/
Writing:
You can use a Google app script for writing to the spreadsheet (reference) OR
You can create a Google form linked to the spreadsheet and simply fill the form from your mobile app whenever you want to add some data to the sheet (reference)
Of all the cloud services, when it comes to Android, Dropbox's Sync API is one of the easiest to implement. Do you need specific code examples on how to sync with Dropbox?
I have an android application, which wants the user to login each time he runs the app. So, the login procedure is simple, using the sqlite dabase file i'm using. I've copied the file in assets folder and doing the necessary modifications. But, the database file is of no use unless it is on the server. I don't have any server so i'm thinkin of keeping the database file on dropbox, google drive etc and then read or update that file as per user commands. The question is how to do that? I was searching the web for it, and found that the only way is downloading the db file modifying it and the uploading it back. Can anyone give me an example??
Doing that isn't possible unless you have a server.
Because, if you are using dropbox, first you'll have to make your file public in order to download it (Not recommended at all. Compromises security). Then you can use the url to download the file. But you won't be able to upload it back (Unless you are able to login to dropbox through your Android code).
Instead if you a web server with MySQL n PHP, you can easily send POST requests to your server.
I have an SQLite Database on a webserver. I would like to access the database from a typical Java Desktop Application. Presently, I'm doing this thing...
Download the Database file to a local directory, perform the queries as necessary.
But, I'm unable to perform any update queries on this. How can I do this. [ On the actual database]
Another question is, to directly access the database from web in java (is this possible), make direct queries, updates anything etc,.
How can I achieve this type?
I've written code for connection of Java to SQLite and is working pretty fine, if the db file is in local directory. What changes or anything I have to do to establish a link to the file on webserver without having to download the database file.?
Thanks in advance...
CL. is right saying that if you need to access from desktop applications to a web database, SQLite is not an appropriate choice.
Using SQLite is fine in small web sites, applications where your data have to be accessed from and only from the web site itself; but if you need to access your data from - say - your desktop, without downloading the data file, you can't achieve that with SQLite and HTTP.
An appropriate choice for your web application would be MySQL or other client/server database, so that you could be able to connect to the database service from any place other than your web application, provided server access rules set permit that (e.g. firewalls, granted authentication, etc.).
In your usage scenario, you would be facing several orders of problems.
1) Security
You would be forced to violate the safety principle saying that database files must be protected from direct web exposure; in fact, to access your web SQLite database file from your desktop you would be forced to expose it directly, and this is wrong, as anyone would be able to download it and access your data, which by definition must be accessible just by you.
2) Updatability without downloading
Using HTTP to gain access to the database file can only lead to the requested resource download, because HTTP is a stateless protocol, so when you request GET or even POST access to the database, the web server would provide it to you in one solution, full stop.
In extreme synthesis, no chance to directly write back changes to the database file.
3) Updatability with downloading
You could download your file with a HTTP GET request, read data, make changes and the rest, but what if your online database changes in the meanwhile? Data consistency would be easily compromised.
There could be a way
If you give up using HTTP for your desktop application access to the database, then you could pick FTP (provided you have access credentials to the resource).
FTP lets you read data from and write data to files, so - on Linux - you could use FUSE to mount a remote FTP sharing and access it just like if it was connected to your local file system (see this article, for example).
In synthesis, you:
Create a mount point (i.e. a local directory) for FTP sharing
Use curlftpfs to link the remote FTP resource to your mount point
Access to this directory from your application as if it was a conventional directory
This way you could preserve security, keeping the database file from being exposed on the web, and you would be able to access it from your desktop application.
That said, please consider that concurrent access by several processes (desktop app + webserver instance) to a single database file could lead to problems (see this SO post to have an idea). Keep that in mind before architecting your solution.
Finally, in your usage scenario my suggestion is to program some server-side web service or REST interface that, under authentication, let you interact with the database file performing the key operations you need.
It is safe, reliable and "plastic" enough to let you do whatever you want.
EDIT:
MySQL is widely used for web sites or web applications, as it is fast, quite scalable and reasonably reliable. Activating MySQL server is a little bit OT on StackOverflow and quite long-winded to report, but in that case you could google around to find plenty of articles discussing such topic for your operating system of choice.
Then use MySQL JDBC driver to access the database from your Java desktop application.
If your idea is to stick with SQLite, though, you could basically prepare four web endpoints:
http://yourwebsite.com/select
http://yourwebsite.com/insert
http://yourwebsite.com/update
http://yourwebsite.com/delete
(Notice I specified "http", but you could consider moving to SSL encrypted http connection, a.k.a. "https", find details here and here. I don't know which webserver are you running, but still googling a little bit should point you to a good resource to properly configure https.)
Obviously you could add any endpoint you like for any kind of operation, even a more generic execute, but play my game just for a while.
Requests towards those endpoints are POST, and every endpoint receives proper parameters such as:
table name
fields
where clause
... and the like, but most important is security, so you have to remember 2 things:
1. Sign every request. You could achieve this defining a secret operation key (a string which is known to your client and you server but never travels in clear text), and using it in a hashing function to produce a digest which is sent together with other parameters as an incontrovertible proof for the server that that request it's receiving comes from a genuine source. This avoids you to send username and password in every request, which would introduce the problem of password encryption if you don't use https, and involves that the server has to be able to reconstruct the same signature for the same request using the same algorithm. (I flew over this thing at 400Mph, but the topic is too large to be correctly treated here. Anyways I hope this could point you in the right direction.)
2. Properly escape request parameters. "Sanitize" parameters someone calls it, and I think the metaphor is correct. Generally speaking this process involves some filtering operations performed by the server's endpoint, but it basically could be written as "use prepared statements for your queries". If you don't it could be likely that some malicious attacker injects SQL code in requests to exploit your server in some manner.
SQLite is an embedded database and assumes that the database file is directly accessible.
Your application is not an appropriate use of SQLite.
You should use a client/server database.
In any case, you should never make a database directly accessible on the internet;
the data should go through a web service.
Theme : Newspaper updates in android application.
How to fetch or retrieve data from server and post updates on android application . How to manage offline storage means whenever there is no internet connection how the data gone be updated on android application , atleast how it consider showing updates on android application . If any one known this issue please answer about it .
I am actually using php or json as intermediate files for fetching data from server and send updates to android application but its seems to be more complex and if i wont get the permission to access the server side files , how do i manage for updates ? whether is it necessary to have permission to access the server files ?
More about the topics : if i want to syncronise the update with website , how do i handle it or implement it ? i am not asking any sort of coding here .
How to fetch or retrieve data from server and post updates on android application
use HTTPClient.
How to manage offline storage means whenever there is no internet connection how the data gone be updated on android application
I think you don't understand what offline storage means. If there is no internet connection, that's it. You are not able to update your content. Offline storage is useful if you have internet connection, but not everytime. The content you downloaded when you had internet connection can be saved to SQLLite to be loaded when you don't have internet connection.
I am actually using php or json as intermediate files for fetching data from server and send updates to android application but its seems to be more complex and if i wont get the permission to access the server side files , how do i manage for updates ? whether is it necessary to have permission to access the server files ?
Create WebService as an interface. Do not let other system to be able to directly access your files. Or just create a PHP files that basically return Json or XML Data.
Other option : create an RSS.
More about the topics : if i want to syncronise the update with website , how do i handle it or implement it ? i am not asking any sort of coding here .
Create an event to start sync using HTTPClient. If there is new update, save it to SQLLite(for offline storage) and display the content. The event can be triggered during the start of your application or clicking refresh button and if Internet exist.
Update :
There is a new framework called couchbase mobile. You can sync the local mobile db from a couch server. You can insert/update the data locally(offline mode) and then the data can be synced also to the couch server, whenever you have internet connection. This means the need to create HTTPClient is no longer necessary.
For the database, try cloudant.
I'm trying to build an android app with connection to our SQL Server. I have downloaded the jTDS JDBC Driver. I have an jar file and have to copy it to my application's classpath. But where is that? I have copied to my workspace in the project directory where the file ".classpath" is. But it seems not to work.... everytime if I'm at the code where I load the class with
Class.forName("net.sourceforge.jtds.jdbc.Driver");
it says:
The source attachment does not contain the source for the file ClassLoader.class. You can change the source attachment by clicking Change Attachmend Source below"
Any ideas? I'm new to java AND android...
no need of that much of mess.
Simply for Mysql Server Data Access or any live server data access.
Make Use of Web Services
Its like prepare a dynamic page that have all the fetched data result from the server. Your android application need to hit that dyanamic page URL and then simply read the content from the streams and use them in your application.
Genrally large amount of data is expressed in xml format which is then parsed from the application See on google about SAXParser
In short its like a web page that will echo your server data after your app hit the url of that web page to read the data.