Thread: Mysql help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Mysql help


    Hi, i have been banging my head into the wall with this so your help would be awesome! I am making an app that uses a MYSQL database so i am trying to connect to the database and it will not work. This might be more of a Java question, but it is for a Droid app so i am putting it here.

    function in Worker class:

    Code:
    Connection connection = null;
    
    public String connectToDB() {
    	String dbURL = "jdbc:mysql://localhost:3306/database";
    	String username = "root";
    	String password = "pass";
    
    	Class.forName("com.mysl.jdbc.Driver").newInstance();
            connection = DriverManager.getConnection(dbURL, username, password);
    				
            if(connection != null){
    	        conResult = "connected";
    	}else{
    		conResult = "not connected";
    	}
    	return conResult;
    }
    Class that uses above code:

    Code:
    Worker dbWorker = new Worker();
    
    String test = dbWorker.connectToDB();
    Toast t = Toast.makeText(this, test, Toast.LENGTH_LONG);
    t.show();
    i am only showing the code that i think is relevant. i must be missing something i keep getting the toast that says not connected

    i did not add the try/catches to this post to keep it clean.
    i am using eclipse

    things i have tried:
    - i have added the mysql connector to the library and set the path
    - the file is copy to the /ext file and the /bin in my java file
    - the firewall on port 3306 has been disabled
    - my password is correct


    Oh i also started using an older connector mysql-connector-java-3.0.17-ga because someone said that would make it work.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0
    For those of you stuck in my position i figured it out....

    i don't think mysql really works with droid so don't bother even trying the above method..... that is designed more for java.... you have to upload some php to your server to interact with your database for you and use JSON to pass information in between.

    also, FYI droid cannot read localhost because it will look at the device not your PC so make sure you use your IP address in place of localhost

IMN logo majestic logo threadwatch logo seochat tools logo