• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Connexion to Mysql DataBase

Denouche

Lurker
Hi everybody,

I'm new on Android, and I'm trying to connect my program to a Mysql Database. The ling between my Android emulator and my server is OK, the ping is good. Moreother, I checked the connexion with a PhP script and everything is ok.

I would like to connect my program directly to the dataBase, using JDBC, et the J-connector. I added it to my project, and the code I use to etablish the connexion is :
Code:
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String DATABASE_URL = "jdbc:mysql://10.0.2.2/annuaire";

private void initDb() {
try {
            Class.forName(DRIVER);
            DataBaseConnector.connection = DriverManager.getConnection(DATABASE_URL,"root","pass");
        }
        catch (SQLException sqlException) {
            sqlException.printStackTrace();
        }
        catch (ClassNotFoundException classNotFound) {
            classNotFound.printStackTrace();
        }
}

The problem is the I have an exception, and I don't know why. The fonction getConnection(DATABASE_URL,"root",""); throw the exception.
Below, the screen shot with variables of the exception :
mozscreenshot13.png


I'm totally lost, I search for hours and I don't know why I have this exception.

In advance, thank you so much for your help,
Antoine.
 
hi Antoine;
could you please tell me that how you have connected your java file to php file and then this php file to sql server???
i really need to do this thing.

thanks,

Hina
 
Php code, save file with connection.php

Code:
<?php
     mysql_connect("127.0.0.1","root","");
     mysql_select_db("peopledata");
     $q=mysql_query("SELECT * FROM people");
     while($e=mysql_fetch_assoc($q))
        $output[]=$e;
        print(json_encode($output));
    mysql_close();
?>
 
Back
Top Bottom