dimanche 26 avril 2015

Retrieving next Image(s) from Database using ArrayList Java

I'm able to retrieve the first image from the database from ResultSet when JButton is clicked like so:

    if(rs.next()){
        byte[] imageQues = rs.getBytes("questionDesc");
        imageQuestion = new ImageIcon(imageQues);
        lblQuestionDesc.setIcon(imageQuestion);
}

But assuming I want to read these Images through an ArrayList and display the next n Images, I'm not sure if this is correct:

public class Images {
    private byte[] question;

    public Images(byte[] _question){

        this.question = _question;
    }
    public byte[] getQuestion(){
        return this.question;
    }

Another ArrayList I have displays each question (as text) with no problem like so:

public static List<Questions> BindList(){
    try{
        //Get a connection
        //Create Statement...
        //Declare ArrayList
        List<Questions> list = new ArrayList<Questions>();

        while(rs.next()){
            Questions ques = new Questions(rs.getString("questionDesc"));
            list.add(ques);
        }
        return list;
    }catch(SQLException ex1){
    //Exception stuff
    }
    return null;
}
public void ShowQuestions(int index){
    lblQuestion.setText(BindList().get(index).getQuestion());
}

My question is... Is it possible to display images in the same way as I can display the text? And how could I do this? Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire