1. Check out our companion app, Forums for Android! Download from Google Play

Connexion to Mysql DataBase

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

  1. Denouche

    Denouche New Member
    Thread Starter
    5

    May 31, 2010
    1
    0
    5
    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
    5

    Aug 3, 2010
    1
    0
    5
    Student, Internee in an Software House
    Pakistan
    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
    55

    Dec 16, 2011
    158
    0
    55
    chennai
    plz tell me how is connecting mysql connection in android...am a android beginers.so explain it detaily
     
  4. 9571823307

    9571823307 Member
    25

    Mar 27, 2012
    5
    0
    25
    Android developer in MNC
    Udaipur
  5. 9571823307

    9571823307 Member
    25

    Mar 27, 2012
    5
    0
    25
    Android developer in MNC
    Udaipur
  6. 9571823307

    9571823307 Member
    25

    Mar 27, 2012
    5
    0
    25
    Android developer in MNC
    Udaipur
    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...