import java.sql.*; public class Connexion { private Connection con; private Statement stmt; /** Creates a new instance of Connexion */ public Connexion() { String username = "root"; String password = null; String url = "jdbc:mysql://localhost:3306/biblio"; try{ Class.forName("com.mysql.jdbc.Driver"); }catch(java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try{ con = DriverManager.getConnection(url, username, password); System.out.println("OK connexion réussie..."); stmt = con.createStatement(); } catch(SQLException ex){ System.out.println(ex.getMessage()); } } public Statement getStmt() { return stmt; } public Connection getCon() { return con; } }
public void connexion() { try{ Connexion connect = new Connexion(); stmt = connect.getStmt(); con = connect.getCon(); rqt = new Requete(con, stmt); //mise_a_jour(); } catch(Exception ex){ System.out.println(ex.getMessage()); } }