mysql - Using JDBC to access localhost database from any computer -


first up, apologise if duplicate in way, have been trying many different things site several hours no luck. , record, running os x 10.11.5.

i have made simple application using jdbc connect database created stored on localhost (i using phpmyadmin, if help):

@override public void actionperformed(actionevent e) {  // id search int search = integer.parseint(textfield.gettext()); // setting connection database.     string url = "jdbc:mysql://my_ip_address:3306/javadatabase";     string user = "root"; // root user     string password = ""; // no password     connection con = null;      preparedstatement searchid; // used prepared statement include user input     resultset result = null; // results after sql execution      try {         con = drivermanager.getconnection(url, user, password); // connect mysql         // creating prepared statement         searchid = con.preparestatement("select * names id = ?");         // setting parameter user input         searchid.setint(1, search);         result = searchid.executequery(); // execute sql query          while (result.next()) { // loop until end of results              string id = result.getstring("id");             string firstname = result.getstring("firstname");             string lastname = result.getstring("lastname");              textarea1.settext("id: " + id + "\n" +              "first name: " + firstname + "\n" +             "last name: " + lastname + "\n");         }     } catch(sqlexception e1) {         system.out.println("exception caught " + e1.getmessage());     } {         try {             if (result != null) {                 result.close();             }              if (con != null) {                 con.close();             }         } catch(sqlexception e2) {             system.out.println("sqlexception caught " + e2.getmessage());         }     } }   public static void main(string[] args) {      javawithsql newjava = new javawithsql();  } 

now, packaging application executable .jar file, , want able run on else's computer , have access database , return records.

i have tried instructions here , here, without luck. looked @ opening port 3306 on mac, firewall off, doesn't seem problem. have attempted use grant privileges on database in question using:

grant privileges on javadatabase.* '%'@'%' identified ''; 

to no avail. however, does work on other computers when explicitly write computers ip address, this:

grant privileges on javadatabase.* 'root'@'other_computer_ip' identified ''; 

but need able run on lecturer's computer, , in theory, other people's computers, without having know everyone's ip addresses.

how can this? missing something?

edit:

okay, have run command

grant select on javadatabase.* 'remoteuser'@'%' identified ''; flush privileges; 

and works on computer connected same network, need work if connected different network.

i need pointer on one.

you using to '%'@'%' identified '';

i'm not sure if works. should address root user in case.

grant privileges on javadatabase.* 'root'@'%' identified '';


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -