-1

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:

  1. I saved the sql tables in a file (in phpMyAdmin: export->go) and uploaded it to 000webhost.com.
  2. I tried to connect it from the eclipse, not in big success.
  3. 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.

  1. 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!!

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • Ok , that is great Topic , and can`t answer on one question , but i recommend you that course : https://www.coursera.org/course/mobilecloudprogram . – Ramy Sabry May 17 '15 at 14:36
  • http://stackoverflow.com/questions/26124087/how-to-connect-mysql-in-my-android-project/26124751#26124751 – Jamil May 17 '15 at 14:38
  • Ramy, thanks but unfortunatelly i don't have 6 weeks. And i don't need all this material. Softcoder- i saw this post. Didn't work for me... – dennis bergkamp May 17 '15 at 18:32

3 Answers3

1

Simply put file:

mysql-connector-java-5.1.40-bin.jar

in folder

project/WebContent/WEB-INF/lib

Hope that it helps

wscourge
  • 10,657
  • 14
  • 59
  • 80
0

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.

masana
  • 119
  • 3
  • 12
0

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.

  1. 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.

  2. Receive the link of server, user, password etc' to your mail. save it.

  3. Use 'export' to save your data from the old local DB in phpMyAdmin to a text file.

  4. 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.

  5. 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).

  1. 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".

  1. Done. now you are connected. Try to print some data to check it.

Hope i helped.