When I try retrieve the whole record and display it from database. Its showing an error
java.sql.SQLException: Column Index out of range, 8 > 6.
I am not able to figure this out. pls help.
JAVA CODE
public ArrayList viewAllDrivers() {
ArrayList allDrivers=new ArrayList();
try {
String sql= "select * from adddriver ORDER BY dname";
rs =DBConnection.executeQuery(sql);
while(rs.next()) {
ArrayList one = new ArrayList();
one.add(rs.getInt(1));
one.add(rs.getString(2));
one.add(rs.getString(6));
one.add(rs.getString(8));
one.add(rs.getString(9));
one.add(rs.getString(10));
one.add(rs.getInt(11));
allDrivers.add(one);
}
}
catch (Exception ex) {
System.out.println (ex);
}
return allDrivers;
}
PAGE WHERE I AM TRYING TO SHOW THE RESULT
<%
SearchDAO searchDAO = new SearchDAO();
ArrayList all = searchDAO.viewAllDrivers();
int size = all.size();
%>
<table width="95%" align="center" style="border:#D22929 solid 2px;padding:10px;" border="0">
<tr>
<th bgcolor="#D22929" scope="col"><span class="style10">Driver Name </span></th>
<th bgcolor="#D22929" scope="col"><span class="style10">Address</span></th>
<th bgcolor="#D22929" scope="col"><span class="style10">City</span></th>
<th bgcolor="#D22929" scope="col"><span class="style10">Contact</span></th>
<th bgcolor="#D22929" scope="col"><span class="style10">Country </span></th>
<th bgcolor="#D22929" scope="col"><span class="style10">Ation</span></th>
</tr>
<%
for(int i=0;i<size;i++){
ArrayList one=(ArrayList)all.get(i);
%>
<tr style="height:30px; padding:4px;">
<td><div align="center"><%=(String)one.get(1)%></div></td>
<td><div align="center"><%=(String)one.get(2)%></div></td>
<td><div align="center"><%=(String)one.get(3)%></div></td>
<td><div align="center"><%=(String)one.get(4)%> </div></td>
<td><div align="center"><%=(String)one.get(5)%> </div></td>
</tr>
<% } %>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…