Before you shoot at me, i want to say that i searched and found some solutions for my problem, i tried them, but in general no one of them solve my issue.
The problem is that there are a lot of "small" answers for "small" problem, and i think that i have a "huge" problem with understanding.
After this introduction, my problem is:
I build a system that simulate an emergency center.
The center is the dynamic web project, built in java (eclipse), received emergency messages from the application and show the new data on the screen.
What i already have: a dynamic web project, with fabricated data that i created (MySql), and an android application.
What i want to be done is the connect between all parts.
I mean, i don't understand how to create the connection between the android and my web project. All i want is to send from the android a message to the MySql database and to show the new updated database.
What i already tried:
I saved the sql tables in a file (in phpMyAdmin: export->go) and uploaded it to 000webhost.com.
I tried to connect it from the eclipse, not in big success.
I tried this solution:
http://www.trustingeeks.com/connect-android-app-to-mysql-database/
and got stuck in part 4/5-too much errors in eclipse.
I tried this solution:
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
and spent half a day with configurate the ports of xampp and wamp (didn't succeed to avoid conflict).
I saw solutions that told me to upload my database to host server, other told me that my local server (xampp) is good enough. Someone told me to upload all my project, not only the sql tables.
I'm very confused...i didn't think that it will be so difficult.
So all this atemps bring me to write this post and to ask from someone to give me an organized solution, that include all i need to solve this.
Thanks in advance!!
Simply put file:
mysql-connector-java-5.1.40-bin.jar
in folder
project/WebContent/WEB-INF/lib
Hope that it helps
I have some Android apps that communicates with a central server which has a mysql database. To communicate to this data base I use two ways:
1) The one you mentioned, using a php script in the server which connects and updates the mysql database.
2) Using a webservice built in java. I publish it using Glassfish. For me after trying a bunch of possibilities, it was the easiest and fastest one to deploy. What you have to do is export your project to a .war file and upload it to your Glassfish server in the admin page, usually from "your.ip:4848". There you can easily configure where you want to publish your webservice (port number). For the communication from the Android app to the webservice I use a java library called "ksoap2".
In all cases I have my data base, the web service and the php script in the same host machine.
After a lot of days and night, trying to do complicated things, i found a very very simple solution, and i add it here for the next person that will encounter this problem.
Create a new account and database in this site: http://www.freemysqlhosting.net/
Now you have a DB on the net. I will call him new DB.
You have there an option of phpMyAdmin interface. All next instructions are refering to the phpMyAdmin interface there.
Receive the link of server, user, password etc' to your mail. save it.
Use 'export' to save your data from the old local DB in phpMyAdmin to a text file.
Copy it to SQL query in the new DB, and it will add all the data, instead of typing yourself a lot of records.
now all your old data is in the new DB, that standing on a hosting server.
In your mail, you have this message:
Hi
Your account number is: xxxxx
Your new database is now ready to use.
To connect to your database use these details
Host: xxx.freemysqlhosting.net
Database name: name
Database user: user
Database password: password
(according to your password and name, of course).
So, to connect in eclipse we will use this details:
private Connection connectToDB() throws ClassNotFoundException,SQLException
{
Connection connection = null;
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://xxx.freemysqlhosting.net:3306/user","user", "password");
return connection;
}
*my db user and db name are the same, so i don't know if need actually to add here "name" or "user". so if it's not working-try to change one of them to "name".
Done. now you are connected. Try to print some data to check it.
Hope i helped.
Related
New to Android app building. I built our company website using php/mysql and my boss had an android app built previously with, I assume SQLlite, or something. Anyway, he wants me to change the database that it's currently linked with to our mysql db. For the life of me I cannot find anything even resembling a connection string or a query in the file system? In my attached screenshot where would I find this information? Or is it not held in this tree at all?
I would assume the data/model folders, but I've searched every single file in those folders. I really need some help.
SQLite is a local db. There would be no connection string, its literally accessed as part of your process.
You should NOT directly connect to a remote db. Doing so is completely insecure, as it would be putting the password for your db into the app. You need to run a web service, and hit that to get your data. The web service then connects to the db.
You should also probably figure out what the actual project is. With SQLite, you would work offline, based off a copy of the data stored locally. With a remote db, offline use is impossible. Being told to replace SQLite with a remote db and your level of understanding of that in this question shows that one or both of you don't understand what the scope of that change is, and you should make sure you're on the same page and what the best way to achieve the actual goal of your project is.
I've looked around trying to find an answer to this question, but have so far been unsuccessful. I have a current version of an Android mobile application that stores items in the local database, and I'm trying to hook it up to a 'cloud' database (not sure if this is the right term) so that other people that download the app will be able to view and post things to the database.
I have an ec2 service set up, with my LAMP stack installed. I have the database set up on this server ready to go. How do I go about hooking up the Android application so that it can communicate (insert/view/delete items) with the database? I am a new developer so any help/insight/guidance you have is much appreciated!
You haven't mentioned the type of database you have setup on cloud.
I am assuming it to be some kind of relational database (e.g. MySQL).
You can use standard JDBC connection from a regular java code but it is not yet possible (supported) to do it directly from Android code.
I faced a similar issue, what I did was this:
Create a Servlet and deployed it on GAE (Google App Engine).
Make an HTTP request from your android application code to this Servlet (SELECT/UPDATE/DELETE).
Initiate a JDBC connection to your database (on EC2) from that Servlet.
Shoot the SQL statement to the database.
Get the result and send the response back from servlet to your android code.
There may be other better solutions but I could not find any and tried this on my own, it worked like a charm, multiple times.
After writing the previous answer, I kept on thinking of alternate solution.
FYI: This may or may NOT work !
Instead of hosting your servlet on GAE, you can host it on the same EC2 instance as your database, using tomcat or any other package.
This way your android code would communicate directly with the instance that has servlet and database deployed together.
In the servlet, you can shoot SQL queries internally and send the results back to android code.
How to host a servlet in Tomcat 7
Adding new security group and linking it with my instance..worked for me
I am trying to develop a real-time Android application where all contents are stored in server. So, they are available whenever a connection to Internet is available. Also, the application provides communication between users and conversations are stored in the server as well. Nothing is locally stored.
However, I am still cannot decide which database type I can use. I intended to use SQLite but I am not sure if I can really use it or not.
Could you please guide me to the proper database type to my application.
Appreciate your time and efforts.
As its upto you which database you use.
you may Install Lamp (For Linux) or WAMP(for window) . This is a nice database tool and very easy to handle and easy linked with PHP for various database function
I recently developed something similar to what you are talking about and here is what I would suggest you to go for.
Use SQL server to manage the data on your desktop and create a web-service in .Net on Visual Studio.
(Note that as others have already mentioned, it really does not matter what is the database you are using in your server end, because eventually the data is going to come to the Android application from the server in form of either xml or json in the web-service., regardless of what database you are using. So it is totally your wish which database you want to use.)
Then connect to the web-service in your application and set/get data from the remote Database, using SOAP.
Link on how to make a web-service in .NET (does not include the implementation in Android).
Links on how to connect your service with Android : this, this and this.
Is there any sample? I have my android application and I need to connect to mysql server on my machine, what is the best way?
I should not use jdbc, explanation here
Best way to implement Client <-> Server <-> Database architecture in an Android application?
Never never use a database driver across an Internet connection, for any database, for any platform, for any client, anywhere. That goes double for mobile. Database drivers are designed for LAN operations and are not designed for flaky/intermittent connections or high latency.
And should go for:
DefaultHttpClient httpclient = new DefaultHttpClient();
But there is no example in how to open a connection or execute a simple sql statement.
anyone could help me?
You should either use web services or implement an HTTP handler and transfer in a RESTful manner.
I'm a fan of Offline First, meaning your app should be usable without a connection.
To facilitate this, I would recommend using a SQLite local database, and syncing to a remote database when online.
You can use a tool like SymmetricDS or Daffodil Replicator to sync your local and remote databases over HTTP(S).
In order to connect to a MySQL server, you need a MySQL client. Android does not come with any MySQL libraries. You may be able to take a generic Java MySQL library and fudge it to work with Android, but that would be a big undertaking and wasted time.
The link you pointed to already told you that what you're trying to do is wrong in the first place. Don't connect to a database across the internet! You will need something on your server that responds to HTTP requests, looks up data in the database, and sends them back via HTTP. The link already mentioned a few options. You could even write something yourself, although it's most likely easier to use an existing solution than trying to make your own approach safe and hack-proof.
I tried to connect DatabaseServer from an Android Application,initially i faced some issue while i was using jtds, jar package for database Driver Support, instead of using jtds jar file use mysql-Connector jar file for Database Driver Support.
mysql-connector jar file "mysql-connector-java-5.1.24-bin.jar".
put this jar file in projects libs folder.
a little bit code snippet :
`String url="jdbc:mysql://(IP-of databaseServer):3306/DBNAME";`
`String driver="org.gjt.mm.mysql.Driver";`
`String username="XYZ";//user must have read-write permission to Database
`String password= "*********";`//user password
`try{
Class.forName(driver).newInstance();//loading driver
Connection con = DriverManager.getConnection(url,username,password);
/*once we get connection we can execute ths SQL command to Remote Database Server with the help mysql-connector driver over Internet*/
}`
`catch(Exception e){
e.printStackTrace();
}`
I hope it could work.
Cheers
Rajesh P Yadav.
You won't be able to connect directly to a MySQL database with the HttpClient, as the MySQL database doesn't operate on that protocol.
The second part of the answer to the question you linked recommends going with web services and consuming those to communicate with the database server. Which is exactly what you would be able to do with the HttpClient.
If you need to share data between multiple phones, I would recommend exposing it as a web service. If the data only needs to be accessible on that particular phone (and you want to remain relational) you can use sqlite.
I have an application that creates an SQLite database and saves
information to it over the course of a day. At the end of the day i
want to export this database to a web server.
Could anyone point me in the right direction for this?
Should I use httppost or put. I have researched this myself online but
there seems to be so many different ways to explore. The server side
does not exist yet either. I have access to an apache server so i am
hoping to use that.
Could anyone advise me the best/most simple way to do this?
Thanks guys,
Just wanted to let you know that i used the intent provided by the andFTP app in the end. Its very simple to use and details can be found at: http://www.lysesoft.com/support/forums/viewtopic.php?f=5&t=158
Couple of ways ...
you can ftp up the db each day
you can export the data to a csv file and post it to the server; once there you can then import it into the db on the web server
Is it for backup purposes? Or do you require a number of dbs on the web server?
Do you want this to be an automatic or manual transfer? SQLite data is just a file, so (from the SQLite site)... "If SQLite can read the disk file then it can read anything in the database. If the disk file and its directory are writable, then SQLite can change anything in the database. Database files can easily be copied onto a USB memory stick or emailed for sharing." So (provided everything your app needs is set up on the server) just move the file to the server.