Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.univ_aix.iut.TestJdbc;
- /**
- * Hello world!
- *
- */
- //Importer les classes jdbc
- import java.sql.*;
- public class App {
- // Chaine de connexion (constante)
- static String CONNECT_URL = "jdbc:mysql://localhost:3306/FloyDB";
- // La requête de test (constante)
- static final String req = "SELECT NUM_ET, NOM_ET, PRENOM_ET " +
- "FROM ETUDIANT " +
- "WHERE VILLE_ET = 'AIX-EN-PROVENCE'";
- public static void main(String[] args) throws SQLException {
- // Objet materialisant la connexion à la base de données
- try {
- // Création et paramétrage d'une instance OracleDataSource
- Connection conn = DriverManager.getConnection(CONNECT_URL, "root", "mysql");
- // Creation d'une instruction
- Statement stmt = conn.createStatement();
- // Execution de la requete
- System.out.println("Exécution de la requête : " + req + "\n");
- ResultSet rset = stmt.executeQuery(req);
- // Affichage du résultat
- while (rset.next()){
- System.out.print(rset.getInt("NUM_ET") + " ");
- System.out.print(rset.getString("NOM_ET") + " ");
- System.out.println(rset.getString("PRENOM_ET"));
- }
- // Fermeture de l'instruction (libération des ressources)
- stmt.close();
- System.out.println("\nOk.\n");
- } catch (Exception e) {
- e.printStackTrace();// Arggg!!!
- System.out.println(e.getMessage() + "\n");
- }
- }
- }
Add Comment
Please, Sign In to add comment