IndexOutOfBoundsException when reading ResultSet
843854Nov 27 2002 — edited Dec 3 2002Hi, I'm getting an IndexOutOfBoundsException when I read a ResultSet this is the code:
public static IntervalCategoryDataset createGanttDataset() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException{
GanttSeriesCollection collection = new GanttSeriesCollection();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
String url = "jdbc:odbc:times";
Connection connect = DriverManager.getConnection(url,"user","pass");
ResultSet rs;
Statement stmt = connect.createStatement();
String strQry = "SELECT tistiact.act_desc, tistiact.actual_start, tistiact.actual_finish";
strQry = strQry + ", tistiact.orig_late_start, tistiact.orig_late_finish";
strQry = strQry + " from tistiact where tistiact.order_no = 'F3654G1'";
rs = stmt.executeQuery(strQry);
GanttSeries s1 = new GanttSeries("Closed");
GanttSeries s2 = new GanttSeries("Active");
String task;
java.sql.Date act_strt, act_fin, org_strt, org_fin;
while (rs.next()){
task = rs.getString(1);
act_strt = rs.getDate(2);
act_fin = rs.getDate(3);
org_strt = rs.getDate(4);
org_fin = rs.getDate(5);
if ((act_strt!= null)&&(act_fin!=null)){
s1.add(task, new TimeAllocation(date(act_strt), date(act_fin)));
collection.add(s1); }
if ((org_strt!= null)&&(org_fin!=null)) {
s2.add(task, new TimeAllocation(date(org_strt) ,date(org_fin)));
collection.add(s2);}
}
rs.close();
stmt.close();
connect.close();
return collection;
}
catch (SQLException e){
System.out.println(e.getMessage());
System.out.println(e.toString());
}
catch (NullPointerException e){
System.out.println(e.getMessage());
System.out.println(e.toString());
}
catch (IndexOutOfBoundsException e){
System.out.println(e.getMessage());
System.out.println(e.toString());
}
return collection;
}
private static Date date(java.sql.Date dateStr) {
int year, month, day;
String dateString = dateStr.toString();
Date result = dateStr;
try{
System.out.println("String Length: " + dateString.length());
System.out.println("String value: " + dateString);
year = Integer.parseInt(dateString.substring(0,4));
month = Integer.parseInt(dateString.substring(5,7));
day = Integer.parseInt(dateString.substring(8,10));
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
result = calendar.getTime();
return result;
}
catch (IndexOutOfBoundsException e){
System.out.println(e.getMessage());
System.out.println(e.toString());
}
catch (Exception e){
System.out.println(e.getMessage());
System.out.println(e.toString());
}
}
The function date is the function that I called for converting dates... The number of records in the ResultSet is 16. This is the error I got java.lang.IndexOutOfBoundsException: Index -1, Size: 16
Can someone help me?, thanks in advance.
Regards