I'm trying to recuperate a list of data from my DB that depends on the date "datJourCchn" ;
I cloudn't find where is the error; PS: I changed the Date imports to java.sql.Date instead of java.util.Date
here is my code:
CoursChangeDaoImpl
@Override
public List<CoursChange> getAllCoursParDate(Date datJourCchn)
{
System.out.println("date------------->" + datJourCchn);
List<CoursChange> coursChanges =new ArrayList<CoursChange>();
Devise devise =new Devise();
Connection conn = null;
String sql=
"SELECT d.LIB_DEV_DEV , d.LIB_SIGL_DEV , c.DAT_JOUR_CCHN , c.COD_ETAT_CCHN , c.MONT_CABA_CCHN , c.MONT_CABC_CCHN , c.MONT_CVBA_CCHN , c.MONT_CVBC_CCHN ,c.TIME_CCHN ,c.ID_COURS_CHANGE FROM COURS_CHANGE c , DEVISE d where c.COD_DEV_DEV=d.COD_DEV_DEV and c.DAT_JOUR_CCHN=?";
System.out.println("date------------->" + datJourCchn);
try
{
conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setDate(1, datJourCchn);
ResultSet rs=ps.executeQuery();
while(rs.next())
{ CoursChange coursChange =new CoursChange();
coursChange.setIdCoursChange(rs.getInt("ID_COURS_CHANGE"));
coursChange.setCodEtatCchn(rs.getString("COD_ETAT_CCHN"));
coursChange.setMontCabaCchn(rs.getFloat("MONT_CABA_CCHN"));
coursChange.setMontCabcCchn(rs.getFloat("MONT_CABC_CCHN"));
coursChange.setMontCvbaCchn(rs.getFloat("MONT_CVBA_CCHN"));
coursChange.setMontCvbcCchn(rs.getFloat("MONT_CVBC_CCHN"));
devise.setLibDevDev(rs.getString("LIB_DEV_DEV"));
devise.setLibSiglDev(rs.getString("LIB_SIGL_DEV"));
coursChange.setDatJourCchn(rs.getDate("DAT_JOUR_CCHN"));
coursChange.setTimeCchn(rs.getString("TIME_CCHN"));
System.out.println(rs.getInt("ID_COURS_CHANGE"));
System.out.println(rs.getString("LIB_DEV_DEV"));
coursChanges.add(coursChange );
}
rs.close();
ps.close();
}
catch(Exception e)
{
throw new RuntimeException(e);
}
finally
{
try
{
conn.close();
}
catch(SQLException e)
{
}
}
return coursChanges;
}
page.xhtml
<p:calendar id="button" value="#{coursChangeCtr.datJourCchn}"
showOn="button" pattern="MM-dd-yy">
</p:calendar>
<p:commandButton value="submit"
action="#{coursChangeCtr.listCoursPreparedStatement()}" update="AjoutTab" />
<p:dataTable value="#{coursChangeCtr.listCoursPreparedStatement()}" var="cours"
id="AjoutTab" emptyMessage="aucune info!!" rows="5"
style="width:1000px;font-size:13px;margin-left: 25px">
the error is:
Cannot convert 17/04/16 00:00 of type class java.util.Date to class java.sql.Date