Aller au contenu
View in the app

A better way to browse. Learn more.

Forum de Frandroid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Connexion à un serveur MySql

Featured Replies

Posté(e)

Bonjour à tous,

Voilà mon problème. J'essaye de me connecter à ma base de données MySql via JDBC. Je sais que c'est pas top de faire directement appli -------- BD sans couche au milieu, mais avant d'aller plus loin j'aimerais effectuer cette connexion.

Ce que j'ai pour l'instant : une classe de connexion BD, qui charge le driver et tente d'effectuer la connexion (testée dans un projet autre qu'android, ça marche).

Le constructeur est comme suit :

//if the connection doesn't exist
		if (conn == null){				

			properties = prop;				
			DB_driver = properties.getProperty("DBdriver");
			DB_login = properties.getProperty("DBlogin");
			DB_type = properties.getProperty("DBtype");
			DB_address = properties.getProperty("DBaddress");
			DB_password = properties.getProperty("DBpassword");
			// We load the driver then we try to connect
			loadDriver();
			conn = connect();
		}

La méthode connect :

private Connection connect() throws SQLException {


	String url = "jdbc:"+DB_type+":"+DB_address;			

	[b]Connection conn = DriverManager.getConnection(url, DB_login,DB_password);[/b]		

    return conn;		
}

ça plante dans la méthode connect(), à la ligne en gras (alors que ça marche parfaitement hors android).

Voici le logcat correspondant à l'erreur (warnings en fait, les erreurs viennent après) :

03-05 17:26:17.736: WARN/dalvikvm(726): VFY: unable to find class referenced in signature (Ljavax/naming/Reference;)

03-05 17:26:17.746: ERROR/dalvikvm(726): Could not find method javax.naming.Reference.get, referenced from method com.mysql.jdbc.ConnectionProperties$ConnectionProperty.initializeFrom

03-05 17:26:17.746: WARN/dalvikvm(726): VFY: unable to resolve virtual method 3838: Ljavax/naming/Reference;.get (Ljava/lang/String;)Ljavax/naming/RefAddr;

03-05 17:26:17.756: WARN/dalvikvm(726): VFY: rejecting opcode 0x6e at 0x0004

03-05 17:26:17.756: WARN/dalvikvm(726): VFY: rejected Lcom/mysql/jdbc/ConnectionProperties$ConnectionProperty;.initializeFrom (Ljavax/naming/Reference;)V

03-05 17:26:17.756: WARN/dalvikvm(726): Verifier rejected class Lcom/mysql/jdbc/ConnectionProperties$ConnectionProperty;

03-05 17:26:17.768: WARN/dalvikvm(726): Unable to match class for part: 'Lcom/mysql/jdbc/ConnectionProperties$BooleanConnectionProperty;'

03-05 17:26:17.777: WARN/dalvikvm(726): Exception Ljava/lang/RuntimeException; thrown during Lcom/mysql/jdbc/ConnectionProperties;.<clinit>

03-05 17:26:17.777: DEBUG/AndroidRuntime(726): Shutting down VM

03-05 17:26:17.787: WARN/dalvikvm(726): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)

03-05 17:26:17.787: ERROR/AndroidRuntime(726): Uncaught handler: thread main exiting due to uncaught exception

03-05 17:26:17.916: DEBUG/dalvikvm(726): GC freed 4510 objects / 318880 bytes in 106ms

03-05 17:26:17.926: ERROR/AndroidRuntime(726): java.lang.ExceptionInInitializerError

03-05 17:26:17.926: ERROR/AndroidRuntime(726): at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)

03-05 17:26:17.926: ERROR/AndroidRuntime(726): at java.sql.DriverManager.getConnection(DriverManager.java:192)

(...)

Si vous avez ne serait-ce qu'un bout d'idée je suis preneur !

Posté(e)

Android ne contient pas toutes les classes J2SE.

Par ailleurs, je pense que c'est une mauvaise idée d'établir une connexion mysql directement sur ton téléphone...

Posté(e)
  • Auteur

Oui c'est vrai, je me suis un peu renseigné et je vais essayer de mettre en place un serveur pour faire le lien entre le téléphone et la base de données.

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

Account

Navigation

Rechercher

Rechercher

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.