1

I'm connecting with mysql database directly without help of any servers. When i try to connect with mysql using emulator it works fine. but when i use my mobile phone it throws some exception. I don't know what is the problem. please help me with this.

Here is my code :

Connection con;
PreparedStatement ps;
Statement st;
ResultSet rs;
String val = "";
Context cont = this;
View menuItemView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Thread on=new Thread(){
        @Override
        public void run(){
          Log.i("Thread","Running"); 
            try {
                    Class.forName("com.mysql.jdbc.Driver");
                    Log.i("Connection","connected with jdbc");
                    con = DriverManager.getConnection("jdbc:mysql://192.168.1.2:3306/outsidelaundry", "vino" , "vino");
                    Log.i("Connection","connected with database");
                    runOnUiThread(new Runnable() {
                        @Override 
                        public void run() {
                                Toast.makeText(getApplicationContext(), "connected", Toast.LENGTH_LONG).show();
                        }
                    });
            } catch (Exception e) {
                e.printStackTrace();

            }
        }
    };
    on.start();
}

logcat error says :

09-26 14:46:05.474: E/StrictMode(809): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cec370 that was originally bound here
09-26 14:46:05.474: E/StrictMode(809):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
09-26 14:46:05.474: E/StrictMode(809):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
09-26 14:46:05.474: E/StrictMode(809):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
09-26 14:46:05.474: E/StrictMode(809):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
09-26 14:46:05.474: E/StrictMode(809):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
09-26 14:46:05.474: E/StrictMode(809):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-26 14:46:05.474: E/StrictMode(809):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
09-26 14:46:05.474: E/StrictMode(809):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
09-26 14:46:05.474: E/StrictMode(809):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
09-26 14:46:05.474: E/StrictMode(809):  at java.lang.Thread.run(Thread.java:856)
09-26 14:46:05.484: W/ActivityManager(339): Unbind failed: could not find connection for android.os.BinderProxy@4102be08

Solution : I found the solution to this problem. In order to connect your mobile device with mysql database directly to send/receive data you should on your wifi first and not only that but also enable the background data and Auto sync in your device. Background data is the one which allows to travel datas within the devices.

Selvarathinam Vinoch
  • 1,080
  • 3
  • 13
  • 23

1 Answers1

-1

I might not remember this correctly. I think that I had a similar issue with the solution being adding this to Application:

@Override
public void onCreate() {
    try {
        Class.forName("android.os.AsyncTask");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    super.onCreate();
}
cYrixmorten
  • 7,110
  • 3
  • 25
  • 33
  • I don't understand.why should i use this ?? – Selvarathinam Vinoch Sep 26 '13 at 15:35
  • Is simply a suggestion, as I write I recall getting weird logcat errors including AsyncTask and this was the solution. Might very well not be the case for you but I cannot see any reason not to try it. – cYrixmorten Sep 26 '13 at 15:40
  • Searching only gives the 'solution' to disable the Exchange Service: http://stackoverflow.com/questions/13765122/android-emulator-spams-logcat-with-service-com-android-exchange-exchangeservice ... – cYrixmorten Sep 26 '13 at 15:47
  • How about restarting the phone? Tech support suggestion no1 :D – cYrixmorten Sep 26 '13 at 15:57
  • 1
    I found the way..I have to on the wifi and data-sync to connect with mysql.Now it works fine.thanks for your advises. – Selvarathinam Vinoch Sep 26 '13 at 16:13
  • @Vinoch Please edit your question to mention that you found a solution -- or add the solution as a separate answer. – acj Sep 26 '13 at 17:12