private static String previousWeekNumber="SELECT sum(to_number(TO_CHAR(to_date(sysdate),'WW')- to_number(?, '99') , '99') + to_number(?, '99') ) previousWeek FROM Dual" ;//make change for previous week
public static int getPreviousWeekNumber(Connection connect,String offset,String totalWK) throws Exception{
PreparedStatement pStat = null;
ResultSet rs = null;
String previousWeek=null;
try {
if(connect!=null){
//previousWeekNumber=previousWeekNumber.replaceAll("\\$WEEK", offset).replaceAll("\\$TOTALWK", totalWK);
pStat = connect.prepareStatement(previousWeekNumber);
pStat.setString(1, offset);
pStat.setString(2, totalWK);
rs = pStat.executeQuery();
if(rs.next()){
previousWeek = rs.getString("previousWeek");
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
finally{
if(pStat!=null){
pStat.close();
pStat=null;
}
if(rs!=null){
rs.close();
rs=null;
}
}
if(previousWeek!=null){
return Integer.parseInt(previousWeek);
}
else{
return 0;
}
}
public static int getPreviousWeekNumber(Connection connect,String offset,String totalWK) throws Exception{
PreparedStatement pStat = null;
ResultSet rs = null;
String previousWeek=null;
try {
if(connect!=null){
//previousWeekNumber=previousWeekNumber.replaceAll("\\$WEEK", offset).replaceAll("\\$TOTALWK", totalWK);
pStat = connect.prepareStatement(previousWeekNumber);
pStat.setString(1, offset);
pStat.setString(2, totalWK);
rs = pStat.executeQuery();
if(rs.next()){
previousWeek = rs.getString("previousWeek");
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
finally{
if(pStat!=null){
pStat.close();
pStat=null;
}
if(rs!=null){
rs.close();
rs=null;
}
}
if(previousWeek!=null){
return Integer.parseInt(previousWeek);
}
else{
return 0;
}
}