Android + MySQL à l'aide de com.mysql.jdbc.Pilote

Je suis en train d'écrire une application Android qui va se connecter à un serveur MySQL. Pour l'instant, je suis en train de tester le serveur MySQL sur mon ordinateur via XAMPP l'aide de http://localhost:3306/. Le code ci-dessous fonctionne très bien lors de l'essai strictement comme une application JAVA.

import java.sql.*;

public class MySQL{
  public static void main(String[] args) {
    System.out.println("MySQL Connect Example.");
    Connection conn = null;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "database";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "root"; 
    String password = "";
    try {
      Class.forName(driver).newInstance();
      conn = DriverManager.getConnection(url+dbName,userName,password);
      System.out.println("Connected to the database");
      conn.close();
      System.out.println("Disconnected from database");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Cependant lorsque je l'ai ajouter à mon application Android, je reçois l'Exception e d'erreur.

//interact with MySQL!!!
 private View.OnClickListener onSendRequest = new View.OnClickListener() {
  @Override
  public void onClick(View v) {
   EditText username = (EditText) findViewById(R.id.Huusername);
      //   String un = " " + username.getText().toString() + " ";

      System.out.println("MySQL Connect Example.");
      Connection conn = null;
      String url = "jdbc:mysql://localhost:3306/";
      String dbName = "database";
      String driver = "com.mysql.jdbc.Driver";
      String userName = "root"; 
      String password = "";
      try {
        Class.forName(driver).newInstance();
        conn = DriverManager.getConnection(url+dbName,userName,password);
        Toast.makeText(getBaseContext(),
      "Connected to the database.", Toast.LENGTH_LONG)
      .show();
        conn.close();
        Toast.makeText(getBaseContext(),
      "Disconnected form the database.", Toast.LENGTH_LONG)
      .show();
      } catch (Exception e) {
       Toast.makeText(getBaseContext(),
      "Exception e.", Toast.LENGTH_LONG)
      .show();
        e.printStackTrace();
      }


  }
 };

Que je suis compiler mon application Android, je remarque l'instruction suivante dans la Console:

[2011-01-26 16:05:54 - hookup]: Dxwarning: Ignoring InnerClasses attribute for an anonymous inner class
(com.mysql.jdbc.interceptors.ResultSetScannerInterceptor$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

Je suppose que cette déclaration a quelque chose à voir avec l'Exception que j'obtiens. Quelqu'un a travaillé avec MySQL et Android qui pouvait me conduire dans la bonne direction?
Grâce

Vous avez probablement besoin le code source du pilote de sorte que vous pouvez recompiler.

OriginalL'auteur Raddfood | 2011-01-26