java - Connect Android app to phpmyadmin - could not connect error -
hi i'm creating android app , need connect phpmyadmin, following error in logcat ..... com.mysql.jdbc.exceptions.jdbc4.mysqlnontransientconnectionexception: not create connection database server
my mainactivity.java class
import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.menu; import android.view.view; public class mainactivity extends activity { public final static string extra_message = "com.example.kwikfit2.message"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } public void sendmessage(view view) { databaseconnection dbcon = new databaseconnection(); dbcon.connectioncreate("jdbc:mysql://localhost:3306/diss", "root", ""); system.out.println("got here"); intent intent = new intent(this, displaywelcomeactivity.class); startactivity(intent); }
}
my databaseconnection.java
package com.example.kwikfit2; import java.sql.*; public class databaseconnection { public connection connectioncreate(string url, string user, string password){ try{ class.forname("com.mysql.jdbc.driver"); connection con = drivermanager.getconnection(url,user,password); system.out.println("connection established"); return con; }catch(exception e){ system.out.println(e); }return null; }
}
any appreciated,
thanks
as shihan pointed out, don't connect phpmyadmin. it's web-based tool used manage mysql databases.
your code assumes running mysql in localhost android device , doubt that. quick google search didn't find info android version of mysql server. should connect actual server that's running mysql database. note mysql configured allow connections localhost default.
on android don't use jdbc @ all. better have restful service on server , android use interface through http communicate server.
you should check out tutorials sqlite , see if answer problem. it's embedded database that's used in many android applications.
Comments
Post a Comment