jdbc in android, NullPointerException thrown -
public class mainactivity extends actionbaractivity { string id ; string name ; int price; private resultset result; private connection con; string url = "jdbc:mysql://localhost:3306/fyp_restaurant"; string username = "root"; string password = ""; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); try{ class.forname("com.mysql.jdbc.driver").newinstance(); }catch(exception e){ system.err.println("cannot create connection"); } try{ con = drivermanager.getconnection(url, username, password); statement statement = con.createstatement(); string query = "select * product"; result = statement.executequery(query); }catch(exception e){ system.err.println("error"); } try { id = result.getstring("id"); name = result.getstring("name"); price = result.getint("price"); }catch (exception e){ system.out.println(e.getmessage()); } //toast.maketext(getapplicationcontext(), "id" + id + "\nname" + name + "\nprice" + price,toast.length_short).show(); }
i don't know whether jar file in correct directory - should in libs
? using android studio. need add library in android studio?
Comments
Post a Comment