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
| public void rechercheProduit(String lib) throws SQLException, ClassNotFoundException, IOException{
Class.forName("com.mysql.jdbc.Driver");
Properties p = new Properties();
p.load(getClass().getClassLoader().getResourceAsStream("ConfigBoutique.ini"));
this.name=p.getProperty("dbuser");
this.database = p.getProperty("database");
this.passdb = p.getProperty("dbpass");
Connection con = DriverManager.getConnection(database,name,passdb);
Statement stm = con.createStatement();
String reqI = "Select id, libelle, prix From Produit Where libelle LIKE '"+lib+"%'";
try{
ResultSet rs = stm.executeQuery(reqI);
while (rs.next()) {
int id = rs.getInt("id");
String libl = rs.getString("libelle");
float prix = rs.getFloat("prix");
System.out.println (id +" "+ libl + " " + prix);
}
rs.last();
int nbenr = rs.getRow();
if(nbenr<1){
System.out.println("Aucun produit ne correspond au recherche");
}
}catch(SQLException e){
System.out.println("Erreur de la requete");
e.printStackTrace();
}
finally{
if (stm !=null)stm.close();}
} |
Partager