![](//s1.studylibfr.com/store/data-gzf/f8c408a058e167442f7e6584064873f3/1/002082695.htmlex.zip/bg5.jpg)
JDBC 5
Charger un pilote spécifique à la base de données
et obtenir une connexion à la base de données.
import java.sql.*;
public class AfficherEmployes {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DATABASE_URL = "jdbc:mysql://localhost/ressources_humaines";
static final String USER = “user";
static final String PASS = “user";
try {
// Charger le pilote
Class.forName( JDBC_DRIVER );
// etablir la connection
connection = DriverManager.getConnection( DATABASE_URL, USER, PASS);
}// end try
catch ( ClassNotFoundException classNotFound ) {
System.err.prinln(“Impossible de charger le pilote”);
classNotFound.printStackTrace();
System.exit( 1 );
}// end catch
catch ( SQLException sqlException ){
System.err.prinln(“Connetion Impossible”);
sqlException.printStackTrace();
System.exit( 1 );
}// end catch
…