Java mysql

De The Linux Craftsman
Aller à la navigation Aller à la recherche
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Introduction

Connecteur MySQL

[connecteur MySQL]

Inclusion dans le WAR

Mettre le JAR dans le répertoire /WebContent/WEB-INF/lib

Connexion

package fr.sio.pg.test;

import java.sql.DriverManager;

public class TestMysql {

  public static void main(String[] args){
    String bdd = "pg";
    String host = "localhost";
    int port = 3306;
    try{
      Class.forName("com.mysql.jdbc.Driver");
      DriverManager.getConnection("jdbc:mysql://"+host+":"+port+"/"+bdd,"root","password");
      System.out.println("CONNEXION REUSSIE !");
    }catch (Exception e){
      System.out.println("echec pilote : "+e);
    }
  }
}