1. Are you ready for the Galaxy S20? Here is everything we know so far!

Connexion to Mysql DataBase

Discussion in 'Android Development' started by Denouche, May 31, 2010.

  1. Denouche

    Denouche Lurker
    Thread Starter

    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 (Text):
    1. private static final String DRIVER = "com.mysql.jdbc.Driver";
    2. private static final String DATABASE_URL = "jdbc:mysql://";
    4. private void initDb() {
    5. try {
    6.             Class.forName(DRIVER);
    7.             DataBaseConnector.connection = DriverManager.getConnection(DATABASE_URL,"root","pass");
    8.         }
    9.         catch (SQLException sqlException) {
    10.             sqlException.printStackTrace();
    11.         }
    12.         catch (ClassNotFoundException classNotFound) {
    13.             classNotFound.printStackTrace();
    14.         }
    15. }
    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 :

    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,

    1. Download the Forums for Android™ app!


  2. hina zafar

    hina zafar Lurker

    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.


  3. krishnaveni

    krishnaveni Well-Known Member

    plz tell me how is connecting mysql connection in android...am a android beginers.so explain it detaily
  4. 9571823307

    9571823307 Lurker

    Php code, save file with connection.php

    Code (Text):
    1. <?php
    2.      mysql_connect("","root","");
    3.      mysql_select_db("peopledata");
    4.      $q=mysql_query("SELECT * FROM people");
    5.      while($e=mysql_fetch_assoc($q))
    6.         $output[]=$e;
    7.         print(json_encode($output));
    8.     mysql_close();
    9. ?>

Share This Page