법률 사례 모니터링 시스템에서 예정된 사례에 대한 알림을 보내려합니다. 여기 내 코드 -SQL 오류 : 열 인덱스 범위를 벗어남, 2> 1
try{
Class.forName("com.mysql.jdbc.Driver");
cn22= DriverManager.getConnection("jdbc:mysql://localhost:3306/mmtc?zeroDateTimeBehavior=convertToNull", "root", "");
st22=cn22.createStatement();
st23=cn22.createStatement();
st24=cn22.createStatement();
st25=cn22.createStatement();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Not Connected.");
}
DateFormat df=new SimpleDateFormat("M/d/yy");
Date dateobj=new Date();
String datetoday=df.format(dateobj);
Date todaydate=datechanger(datetoday);
DateTime dt1=new DateTime(todaydate);
String fetchdate="Select nextdate from newentry where location='"+Login.locationofcurrentuser+"'";
String fetchdatecount="select count(*) as total from newentry where location='"+Login.locationofcurrentuser+"'";
ResultSet rsdash=st23.executeQuery(fetchdate);
ResultSet rsdashcount=st24.executeQuery(fetchdatecount);
String dategetter="Select caseno from newentry where location='"+Login.locationofcurrentuser+"'";
ResultSet rss786=st25.executeQuery(dategetter);
if(rsdashcount.next()){
int size=rsdashcount.getInt("total");
ArrayList<String> a=new ArrayList<String>();
ArrayList<String> caseno=new ArrayList<String>();
while(rss786.next()){
int y=1;
while(y<=size){
caseno.add(rss786.getString(y++));
}
}
ArrayList<Date> dates=new ArrayList<Date>();
while(rsdash.next()){
int z=1;
while(z<=size){
a.add(rsdash.getString(z++));
}
}
for(int i=0;i<size;i++){
dates.add(datechanger(a.get(i)));
DateTime dt2=new DateTime(dates.get(i));
int gap=Days.daysBetween(dt1,dt2).getDays();
ArrayList<String> b=new ArrayList<String>();
if (gap<4){
b.add("Upcoming case-"+caseno.get(i)+" due on-"+a.get(i)+"");
System.out.println(b);
}
notification.setText(b.toString());
}
}else
{
notification.setText("No Upcoming Cases.");
}
내 newentry 테이블에 하나의 항목이 있으면 그것은 잘 작동하고 대시 보드에도 알림을 던집니다. 는 최대한 빨리 테이블의 두 번째 항목을로 내 코드의
java.sql.SQLException: Column Index out of range, 2 > 1.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.ResultSetImpl.checkColumnBounds(ResultSetImpl.java:831)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5774)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5693)
at mmtc.Dashboard.<init>(Dashboard.java:79)
라인 79이 내 첫 번째 프로젝트이며, 내가 배우고
caseno.add(rss786.getString(y++));
을 - 이것도 오류 -는 SQL을 던졌습니다. 미리 감사드립니다.
이제 완벽하게 작동합니다. 감사 :) –