[TUTORIAL] Connecting to MySQL database

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Re: [TUTORIAL] Connecting to MySQL database

Postby snoopy007 » Sat Feb 26, 2011 11:38 am

My php file is the same file posted up.
My Data base is installed on WampServer on localhost. i created a new directory named "exemple" under C:\wamp\www
my php file is named test.php
So my URL is like this : http://10.0.2.2/exemple/test.php
So good luck
snoopy007
Freshman
Freshman
 
Posts: 5
Joined: Sat Feb 26, 2011 4:57 am

Top

Re: [TUTORIAL] Connecting to MySQL database

Postby schofeild » Sat Feb 26, 2011 12:26 pm

hey thanks for bearing with me....one final question snoopy...which version of eclipse r u using...i am using eclipse 3.6 which is known to have some issues with android...

by d way thanks a ton :wink:
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby snoopy007 » Sat Feb 26, 2011 5:49 pm

am using Eclipse 3.5.1
Good luck
snoopy007
Freshman
Freshman
 
Posts: 5
Joined: Sat Feb 26, 2011 4:57 am

Re: [TUTORIAL] Connecting to MySQL database

Postby schofeild » Sun Feb 27, 2011 2:27 pm

hey really appreciate ur help :wink: ....nothing has worked so far...i really dont know what is the problem?? :roll:
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby moktar » Tue Mar 08, 2011 12:29 am

@schofeild
It might be obvious linux savvy folks, but trying to access localhost or 127.0.0.1 with the android emulator in order to access a local server for testing won’t get you anywhere. That’s because the IP is used internally by the undlying linux as you might have guessed.

Luckily there’s an IP you can use to achieve hitting your local apache/tomcat/whatever : 10.0.2.2

in my case :
public static final String KEY_121 = "http://10.0.2.2:8888/getAllPeopleBornAfter.php";
it Finaly works for me :D
moktar
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Mar 08, 2011 12:24 am

Re: [TUTORIAL] Connecting to MySQL database

Postby pnkflydgr » Tue Mar 08, 2011 8:57 pm

Hey schofield, I was having the same problem. It was a little complicated to fix. I checked my logcat and is was showing a NetworkOnMainThreadException. Basically, it didn't like me having a network connection in my main UI Thread (http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html). You must either use a handler or a AsyncTask<> object. Check out this site for tutorials (http://www.vogella.de/articles/AndroidPerformance/article.html). I used the Async method and just put everything from getServerData(String) inside the doInBackground(String[]) method. I'm still having problems with ConnectionTimeout, but at least I feel like I'm getting closer.
pnkflydgr
Freshman
Freshman
 
Posts: 2
Joined: Tue Mar 08, 2011 8:37 pm

Top

Re: [TUTORIAL] Connecting to MySQL database

Postby mo5ito » Wed Mar 09, 2011 2:08 pm

@pnkflydgr
hey i've got the same probleme,all you have to do is to erase
<uses-sdk android:minSdkVersion="11" /> From the android manifest
and don't forget to insert : <uses-permission android:name="android.permission.INTERNET" />
8)
don't need handler or a AsyncTask<>
mo5ito
Junior Developer
Junior Developer
 
Posts: 13
Joined: Wed Mar 09, 2011 9:33 am

Re: [TUTORIAL] Connecting to MySQL database

Postby schofeild » Wed Mar 09, 2011 2:17 pm

hey guys thanks....i finally was able to run the application..there seem to be some issues with my pc...when i ran the same code om my laptop i got the output...strange!! :wink:
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby pnkflydgr » Wed Mar 09, 2011 4:52 pm

@mo5ito
I figured there was a way to revert (ie...deleting sdkversion11). But I really dislike going backwards. Plus I think it's best practice to do database calls in a thread other than the main UI anyway. Otherwise you might eventually run into the ANR dialog. View best practices to avoid mentioned here: http://developer.android.com/guide/practices/design/responsiveness.html

Thanks All. This has been an extremely helpful tutorial.
pnkflydgr
Freshman
Freshman
 
Posts: 2
Joined: Tue Mar 08, 2011 8:37 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby n3wbie » Sun Mar 27, 2011 6:24 pm

hi there......i try to connect my app to the database on my host...and yes it works, when i try to display some of my data eg: username using textview it works too, but the problem is when i try using list menu to display the name it doesn't work, could you please help me with this....
n3wbie
Freshman
Freshman
 
Posts: 3
Joined: Sun Mar 27, 2011 5:20 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby triplezero » Tue Mar 29, 2011 9:57 am

Hi whitehat,
thanks a lot for the tutorial.
It is work, but only at my device (samsung galaxy spica i5700).
when connected to emulator, it is not work? any idea why?
in emulator i'm sure the internet working, as i can open google from web broswer.
the emulator not show any error, just show http://xx.... (i think is the KEY_121 string)
triplezero
Freshman
Freshman
 
Posts: 6
Joined: Tue Mar 29, 2011 9:51 am

Re: [TUTORIAL] Connecting to MySQL database

Postby xelopan » Wed Mar 30, 2011 7:54 am

Thank you very much for the tutorial.. It's very useful
xelopan
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Mar 25, 2011 2:51 am

Re: [TUTORIAL] Connecting to MySQL database

Postby o0oKodako0o » Sun Apr 03, 2011 10:34 am

I've just use this code but it only show the value of string KEY_121 in my emulator
in my case is :"http://localhost/people.php"
someone help me?
o0oKodako0o
Freshman
Freshman
 
Posts: 4
Joined: Sun Apr 03, 2011 10:28 am

Re: [TUTORIAL] Connecting to MySQL database

Postby schofeild » Sun Apr 03, 2011 1:41 pm

hey if u r running it on an emulator using local host then you have to use special network alias 10.0.2.2 instead of using localhost....so ur url should look like this:

http://10.0.2.2/connectivity/proj.php (connectivity is the folder name and proj.php is ur file)

hope this helps :wink:
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby o0oKodako0o » Sun Apr 03, 2011 2:58 pm

after hours i can run it but it still appear (the value of string KEY_121)
i'll try to get only name or id but it still appear all (include id, name, sex and birthyear)
alright, i'll try for another prj
thanks for the tutorial! so great!
o0oKodako0o
Freshman
Freshman
 
Posts: 4
Joined: Sun Apr 03, 2011 10:28 am

Top
PreviousNext

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 2 guests