1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
public List<Livre> afficherLivres()
{
List<Livre> al = new ArrayList<Livre>() ;
try
{
Class.forName(driver);
//Connexion a* la BDD//
conn = DriverManager.getConnection(url, "root", "sam220889");
stmt = (Statement) conn.createStatement();
//Requete SQL//
rs = stmt.executeQuery("select * from cataloguelivre");
while(rs.next())
{
String titreLivre = rs.getString(1);
String auteur = rs.getString(2);
int prixLivre = rs.getInt(3);
int stock = rs.getInt(4);
Livre livre = new Livre(titreLivre, auteur, prixLivre, stock);
al.add(livre);
}
}
catch(SQLException exc)
{
System.out.println("SQLException : " + exc.getMessage());
System.out.println("SQLState " + exc.getSQLState());
}
catch (ClassNotFoundException exc)
{
exc.printStackTrace();
}
return al ;
} |