Server migration authored by Ferret Renaud's avatar Ferret Renaud
<table>
<thead>
<tr>
<th width="200px"><h6>[:rewind: Exo Précédent](/Exo03-Banque/1%5D-Banque-p1)</h6></th>
<th colspan="6" width="600px"><h1 align="center">04 - Java - JDBC</h1></th>
<th width="200px"><h6 align="right">[Exo Suivant :fast_forward:](/Exo05-IO/1%5D-IO-Fichiers)</h6></th>
</tr>
</thead>
<tbody>
<tr>
<td>&nbsp;</td>
<td align="center">[:one:](/Exo04-JDBC/1%5D-JDBC-Base)<br/>JDBC</td>
<td align="center">:white_check_mark:<br/>MySQL</td>
<td align="center">[:three:](/Exo04-JDBC/3%5D-HSQL)<br/>HSQL</td>
<td align="center">[:four:](/Exo04-JDBC/4%5D-PostgreSQL)<br/>PostgreSQL</td>
<td align="center">[:five:](/Exo04-JDBC/5%5D-Première-classe-Java)<br/>Une classe Java</td>
<td align="center">[:six:](/Exo04-JDBC/6%5D-Banque-p6)<br/>Partie 6</td>
<td>&nbsp;</td>
</tr>
</tbody>
<tfoot>
<tr align="right">
<td colspan="8">
<h6>:copyright: 2019 - <a href="mailto:admin@ferretrenaud.fr">FERRET Renaud</a></h6>
</td>
</tr>
</tfoot>
</table>
***
# Installation
Installez une base MySQL sur votre ordinateur, téléchargez [MySQL](http://dev.mysql.com/downloads/) sur [http://dev.mysql.com/downloads/](http://dev.mysql.com/downloads/)
Lors de l'installation, **notez bien** le mot de passe que vous aurez choisi pour l'utilisateur root.
**Important** :
* Ne pas installer MySQL 8, rester sur une version 5. La 8 est incompatible avec certain outils que nous manipulerons plus tard.
* Ne pas installer un [WAMP](http://www.wampserver.com/) juste pour MySQL, une enclume ne sert pas à planter un clou.
Vous aurez surement besoin d'un client pour manipuler votre base, au cas où Workbench ne vous convient pas, vous pouvez installer l'un de ceux la :
* [DBeaver](https://dbeaver.io/)
* [Heidi SQL](https://www.heidisql.com/)
* [SQuirreL SQL](http://squirrel-sql.sourceforge.net/)
# Chargement des données
Lancez l'utilitaire Workbench et importez la base qui se trouve dans le dossier db de l'exercice, fichier **banque_mysql.sql**.
![00](uploads/f1c437331f16aa1cd6d02d106e1d51db/00.png)
![01](uploads/e96132fb6d6c0f8f16f64e0b4328e087/01.png)
![02](uploads/1bbb80e2b862f94ee58ea28bf3d3a366/02.png)
![03](uploads/ff766570fe1de12261490d0757e0c886/03.png)
# Identification du driver
Hormis dans le cas de ODBC Windows, il nous faut un driver afin que le code Java puisse accéder aux données qui sont dans la base
Le driver est dépendant de la base, vous en avez pour Oracle, DB2, MySQL, SQL Server ..., on peut les télécharger sur le site de chaque éditeur.
Regardez sur le site de l'éditeur de votre base, la version et le nom du driver Java
Pour MySQL ils se trouvent sur [http://dev.mysql.com/downloads/connector/j/](http://dev.mysql.com/downloads/connector/j/).
Vous pouvez aussi regarder sur le repository Maven.
# Ajout du driver pour Maven
Créez un nouveau projet Maven dans Eclipse, **projetBd**.
Reprenez le même fichier **pom.xml** que dans les exercices précédents.
Indiquez dans votre fichier **pom.xml** la dépendance vers le driver Java via l'usage des *dependency* :
```xml
<project>
...
<dependencies>
<!-- Pour la base MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!-- Vous pouvez changer le numero de version -->
<version>8.0.15</version>
</dependency>
</dependencies>
</project>
```
*Remarque* : la version 8 du driver est compatible avec la version 5 de MySQL.
*Rappel* : Après toutes modifications faites sur le fichier **pom.xml**, faites un clic droit sur votre projet puis `Maven - Update Project ...`
***
<table>
<thead>
<tr>
<th width="200px"><h6>[:rewind: Exo Précédent](/Exo03-Banque/1%5D-Banque-p1)</h6></th>
<th colspan="6" width="600px"><h1 align="center">04 - Java - JDBC</h1></th>
<th width="200px"><h6 align="right">[Exo Suivant :fast_forward:](/Exo05-IO/1%5D-IO-Fichiers)</h6></th>
</tr>
</thead>
<tbody>
<tr>
<td>&nbsp;</td>
<td align="center">[:one:](/Exo04-JDBC/1%5D-JDBC-Base)<br/>JDBC</td>
<td align="center">:white_check_mark:<br/>MySQL</td>
<td align="center">[:three:](/Exo04-JDBC/3%5D-HSQL)<br/>HSQL</td>
<td align="center">[:four:](/Exo04-JDBC/4%5D-PostgreSQL)<br/>PostgreSQL</td>
<td align="center">[:five:](/Exo04-JDBC/5%5D-Première-classe-Java)<br/>Une classe Java</td>
<td align="center">[:six:](/Exo04-JDBC/6%5D-Banque-p6)<br/>Partie 6</td>
<td>&nbsp;</td>
</tr>
</tbody>
<tfoot>
<tr align="right">
<td colspan="8">
<h6>:copyright: 2019 - <a href="mailto:admin@ferretrenaud.fr">FERRET Renaud</a></h6>
</td>
</tr>
</tfoot>
</table>
\ No newline at end of file