ArrayList et base de données
Bonjours,
voilà, j'ai ma classe EtabModel:
Code:
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
| public class EtabModel
{
//Attributs
private String denominationEts="";
private String siegeSocial="";
//Accessors
public String getDenominationEts()
{
return denominationEts;
}
public String getSiegeSocial()
{
return siegeSocial;
}
/**
* Default constructor
*/
public EtabModel()
{
}
/**
* Constructor from a resultSet
*@throws SQLException
*/
public EtabModel(ResultSet rst) throws SQLException
{
while(rst.next()){
denominationEts=rst.getString("denominationEts");
siegeSocial=rst.getString("siegeSocial");
}
}
} |
et une des méthodes de ma classe BaseDonnees:
Code:
1 2 3 4 5 6 7 8
| public ResultSet lireEts(int id)throws SQLException, ClassNotFoundException{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection=DriverManager.getConnection("jdbc:odbc:busnessplan");
Statement statement=connection.createStatement();
String sql=("select * from etablissements where idEts='"+id+"'");
ResultSet rst=statement.executeQuery(sql);
return rst;
} |
J'aimerais donc créer autant d'établissement que je veux et les mettre dans une ArrayList pour après afficher la dénominationEts.
Voici mon code:
Code:
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
| class EssaiTab extends JFrame
{
public static void main(String[] argv)
{
JFrame monCadre=new JFrame();
JLabel label=new JLabel();
BaseDonnees bdd=new BaseDonnees();
JPanel panel=new JPanel();
FlowLayout disposition=new FlowLayout();
ArrayList liste=new ArrayList();
panel.setLayout(disposition);
try{
for(int i=1;i<4;i++)
{
liste.add(new EtabModel(bdd.lireEts(i)));
}
EtabModel etab1=(EtabModel)liste.get(0);
String denoEts=(String)etab1.getDenominationEts();
label.setText(denoEts);
panel.add(label);
}
catch(Exception e){
System.out.println("Erreur lors de l'ouverture de la base de données:"+ e.getMessage());
}
monCadre.setContentPane(panel);
monCadre.setVisible(true);
}
} |
l'erreur est:
note:EssaiTab.java uses unchecked or unsafe operations
note: Recompile with _Xlint: unchecked for details
J'ai regardé sur le net pour comprendre cette erreur mais solution en anglais (mon niveau s'améliore mais n'est vraiment pas encore au top):(
merci pour votre aide
claire