Différences entre versions de « Java mysql »
Aller à la navigation
Aller à la recherche
(Page créée avec « = Introduction = == Connecteur MySQL== https://dev.mysql.com/downloads/connector/j/ connecteur MySQL == Inclusion dans le WAR == Mettre le JAR dans le répertoire ''/W... ») |
|||
| Ligne 4 : | Ligne 4 : | ||
== Inclusion dans le WAR == | == Inclusion dans le WAR == | ||
Mettre le JAR dans le répertoire ''/WebContent/WEB-INF/lib'' | Mettre le JAR dans le répertoire ''/WebContent/WEB-INF/lib'' | ||
| + | |||
| + | == Connexion == | ||
| + | |||
| + | <source lang="java"> | ||
| + | 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); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </source> | ||
Version actuelle datée du 1 juillet 2016 à 11:10
Introduction
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);
}
}
}