How can i get rid of this error, the output is correct but i still get the error of "java.lang.ArrayIndexOutOfBoundsException:8". I try to output the result of query into JLabel.
private void PosName(){
try{
String sql = "SELECT * FROM Position";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
ArrayList<String> pos = new ArrayList<>();
while(rs.next()){
pos.add(rs.getString("PositionName"));
}
String[] positionname = new String[pos.size()];
positionname = pos.toArray(positionname);
int v = 50;
for(int i = 0; i <= 100; i++){
JLabel labels1 = new JLabel();
labels1.setBounds(50,v,80,20);
labels1.setText(positionname[i]);
v+=40;
jPanel3.add(labels1);
}
jPanel3.repaint();
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
the output is :
please help me to solve this problem