Connexion to Mysql DataBase


Last Updated:

  1. Denouche

    Denouche New Member This Topic's Starter

    Joined:
    May 31, 2010
    Messages:
    1
    Likes Received:
    0
    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://10.0.2.2/annuaire";
    3.  
    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 :
    [​IMG]

    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.
     

    Advertisement
  2. hina zafar

    hina zafar New Member

    Joined:
    Aug 3, 2010
    Messages:
    1
    Likes Received:
    0
    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
     
  3. krishnaveni

    krishnaveni Well-Known Member

    Joined:
    Dec 16, 2011
    Messages:
    158
    Likes Received:
    0
    plz tell me how is connecting mysql connection in android...am a android beginers.so explain it detaily
     
  4. 9571823307

    9571823307 Member

    Joined:
    Mar 27, 2012
    Messages:
    5
    Likes Received:
    0
  5. 9571823307

    9571823307 Member

    Joined:
    Mar 27, 2012
    Messages:
    5
    Likes Received:
    0
  6. 9571823307

    9571823307 Member

    Joined:
    Mar 27, 2012
    Messages:
    5
    Likes Received:
    0
    Php code, save file with connection.php

    Code (Text):
    1. <?php
    2.      mysql_connect("127.0.0.1","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

Loading...