[TUTORIAL] Connecting to MySQL database

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

Re: [TUTORIAL] Connecting to MySQL database

Postby ajaypatelaj » Tue Apr 05, 2011 6:12 am

hay can you please put some insert update delete code for it ??
ajaypatelaj
Junior Developer
Junior Developer
 
Posts: 22
Joined: Mon Apr 04, 2011 12:54 pm

Top

Re: [TUTORIAL] Connecting to MySQL database

Postby ajaypatelaj » Tue Apr 05, 2011 8:04 am

thanks. a lot its work fro me.....

those are having problem that they can see just url on your screen :idea: ......Ans is they forget to add this code | <uses-permission android:name="android.permission.INTERNET" /> |in your androidmanifest.xml :D
ajaypatelaj
Junior Developer
Junior Developer
 
Posts: 22
Joined: Mon Apr 04, 2011 12:54 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby nls » Fri Apr 08, 2011 3:41 pm

great tutorial.. :) i was searching for the database connectivity from many days ..but guys please help me out .. when i run the ode i get url ... how to solve this ???? n i am using wamp server .. i am waiting .. thank u :)
nls
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Apr 08, 2011 3:26 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby nls » Fri Apr 08, 2011 3:47 pm

@ajay patel raj
hey buddy itried it but still also m getting the url on the screen :(
nls
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Apr 08, 2011 3:26 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby nls » Fri Apr 08, 2011 4:20 pm

hey m getting these errors in ddms console


[2011-04-08 18:14:32 - ddms]null
java.lang.NullPointerException
at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213)
at com.android.ddmlib.Client.sendAndConsume(Client.java:573)
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
at com.android.ddmlib.Client.getJdwpPacket(Client.java:670)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)

[2011-04-08 18:14:32 - ddms]null
java.lang.NullPointerException
at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213)
at com.android.ddmlib.Client.sendAndConsume(Client.java:573)
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
at com.android.ddmlib.Client.getJdwpPacket(Client.java:670)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
can any one help me ???? :) still m getting url on the screen :(
nls
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Apr 08, 2011 3:26 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby schofeild » Sat Apr 09, 2011 4:58 am

hey nls,
make sure ur wamp server is online when u r running this application .
If this does not work...then one option is u can try running the same application on another pc...it worked for me...i know its strange!!
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Top

Re: [TUTORIAL] Connecting to MySQL database

Postby nls » Sat Apr 09, 2011 5:43 am

@schofield
hey i tried whatever you said but its giving the same url .... :( buddy i need your help as am doing the final year project and only this is the part where i got struck :( and i am geeting ddm error... what does it mean ?? :)
nls
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Apr 08, 2011 3:26 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby nls » Sat Apr 09, 2011 6:20 am

@schofeild
and wen i run the php on my browser i got this warning...


Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on '10.0.2.2' (10060) in C:\wamp\www\db\n.php on line 3

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\db\n.php on line 9
null


does it causing to display the url on the screen ??? :)
nls
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Apr 08, 2011 3:26 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby nls » Sat Apr 09, 2011 6:37 am

@schofeild
hey i solved it .... :) actually in php script instead of using 10.0.2.2 i used 127.0.0.1 :) n it worked out :) btw thank u very much for responding :)
nls
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Apr 08, 2011 3:26 pm

Re: [TUTORIAL] Connecting to MySQL database

Postby o0oKodako0o » Sat Apr 09, 2011 3:46 pm

i see you use code
Code: Select all
json_data.getString("abc")

because after query there's one row as a result of each column.

I want to get two or more row as results of each column and pass it througt activity by intent. sb help me??
o0oKodako0o
Freshman
Freshman
 
Posts: 4
Joined: Sun Apr 03, 2011 10:28 am

Re: [TUTORIAL] Connecting to MySQL database

Postby o0oKodako0o » Sat Apr 09, 2011 4:54 pm

o0oKodako0o wrote:i see you use code
Code: Select all
json_data.getString("abc")

because after query there's one row as a result of each column.

I want to get two or more row as results of each column and pass it througt activity by intent. sb help me??


i've solved. hehe! put all elements in an arrayList and display it!
o0oKodako0o
Freshman
Freshman
 
Posts: 4
Joined: Sun Apr 03, 2011 10:28 am

Re: [TUTORIAL] Connecting to MySQL database

Postby basuhampali » Sun Apr 10, 2011 4:07 pm

Thanks Whitehat.......
basuhampali
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Apr 08, 2011 9:37 am

Re: [TUTORIAL] Connecting to MySQL database

Postby shantanuChandalia » Tue May 03, 2011 7:20 am

hey ,

I am using the same code and getting some unknown error. Can you please check the code and rectify.

Code: Select all
package lipi.test.conn;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class testConn extends Activity {
    /** Called when the activity is first created. */
    public TextView txt;
    public TextView txtErr;
    @Override   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LinearLayout rootLayout = new LinearLayout(getApplicationContext());
        txt = (TextView)findViewById(R.id.textView1);
        txtErr = (TextView)findViewById(R.id.textView2);       
        rootLayout.addView(txt);
        rootLayout.addView(txtErr);
        setContentView(rootLayout);       
        txt.setText("Connecting...");     
        txt.setText(getServerData(KEY_121));
    }
   
    public static final String KEY_121 = "http://www.xxxyyy.com/mobile/test.php";

    private String getServerData(String returnString)
    {          
             InputStream is = null;          
             String result = "";
           ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        
           try{
                   HttpClient httpclient = new DefaultHttpClient();
                   HttpPost httppost = new HttpPost(KEY_121);
                   httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                   HttpResponse response = httpclient.execute(httppost);
                   HttpEntity entity = response.getEntity();
                   is = entity.getContent();
           }
           catch(Exception e)
           {
                 txtErr.setText("Error in http connection "+e.toString());
                 Log.e("log_tag", "Error in http connection "+e.toString());
           }
           try
           {
                   BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                   StringBuilder sb = new StringBuilder();
                   String line = null;
                   while ((line = reader.readLine()) != null)
                   {
                           sb.append(line + "\n");
                   }
                   is.close();
                   result=sb.toString();
           }
           catch(Exception e)
           {
               txtErr.append("Error converting result "+e.toString());
              Log.e("log_tag", "Error converting result "+e.toString());
           }       
           try
           {
                   JSONArray jArray = new JSONArray(result);
                   for(int i=0;i<jArray.length();i++){
                           JSONObject json_data = jArray.getJSONObject(i);                        
                           Log.i("log_tag",", TOP_GROUP_CD: "+json_data.getInt("TOP_GROUP_CD")+
                                   ", TRGT: "+json_data.getInt("TRGT")+
                                   ", REG_CD: "+json_data.getInt("REG_CD"));
                           returnString = returnString + jArray.getJSONObject(i) + "\n\t";
                   }
           }
           catch(JSONException e)
           {
              txtErr.setText("Error parsing data "+e.toString());   
              Log.e("log_tag", "Error parsing data "+e.toString());
           }
           return returnString;
       }   
}


Initially i was getting the error : java.lang.string cannot be converted into JSONArray. As discussed in the thread i created a new AVD, it stopped giving an error and now its saying some unexpected error has occured. Check if i did something wrong.

Regards , Shantanu Chandalia
shantanuChandalia
Once Poster
Once Poster
 
Posts: 1
Joined: Tue May 03, 2011 7:14 am

Re: [TUTORIAL] Connecting to MySQL database

Postby owjian87 » Sun May 22, 2011 5:28 am

Hi,

I've able to run the code on my android virtual device on eclipse.
However, I cant see the output on the virtual device screen.
Could anyone provide help here on how to output the data selected from the MySQL database and output to the virtual device screen ?
owjian87
Once Poster
Once Poster
 
Posts: 1
Joined: Sun May 22, 2011 5:25 am

Re: [TUTORIAL] Connecting to MySQL database

Postby O1DMBFan » Mon May 23, 2011 11:01 pm

GREAT TUTORIAL!

I got it all setup and I'm having the same problem as many of the users here, where the url is only displayed on the app screen. My LogCat reads:

Error in http connection java.net.SocketException: Permission denied

My permissions are set as suggested int he Manifest. I have the app set to connect to a webserver running the php script that seems to output correctly when navigated to. I am running this in an emulator and using Eclipse Helios 1.3.2 Service Release 2
O1DMBFan
Freshman
Freshman
 
Posts: 5
Joined: Sun May 22, 2011 5:29 pm

Top
PreviousNext

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 6 guests