Search code examples
springjdbctemplate

Le serveur a rencontré une erreur interne qui l''a empêché de satisfaire la requête


I'm using JdbcTemplate in Spring for the first time;

I want to recuperate data from the DB; I don't no what's my errors ;

please help me to resolve this problem and by giving a helpful courses to understand using JdbcTemplate in spring;

here is my code:

CoursChangeDaoImpl

 public List<CoursChange> listeCours(Date datJourCchn)
 {

 String sql=
 "SELECT * FROM COURS_CHANGE c   where  c.DAT_JOUR_CCHN=:DAT_JOUR_CCHN";
 
 List<CoursChange> coursChange= jdbcTemplate.query(sql,new Object[]          /*******/
 {datJourCchn},new CoursChangeMapper());
 return coursChange;

 }



 class CoursChangeMapper implements RowMapper<CoursChange>{
 @Override
 public CoursChange mapRow(ResultSet resultSet, int rwNum) throws
 SQLException {
 CoursChange coursChange =new CoursChange();
 coursChange.getDevise().getLibDevDev();
 coursChange.getDevise().getLibSiglDev();
 coursChange.getCodEtatCchn();
 coursChange.getMontCabaCchn();
 coursChange.getMontCabcCchn();

 return coursChange;
 }


 }

 class CoursRowMapper implements RowMapper{

 @Override
 public Object mapRow(ResultSet result, int rowNum) throws SQLException {

 CoursChange coursChange =new CoursChange();
 coursChange.setIdCoursChange(result.getInt("ID_COURS_CHANGE"));
 coursChange.setCodEtatCchn(result.getString("COD_ETAT_CCHN"));
 coursChange.setMontCabaCchn(result.getFloat("MONT_CABA_CCHN"));
 coursChange.setMontCabcCchn(result.getFloat("MONT_CABC_CCHN"));
 coursChange.setMontCvbaCchn(result.getFloat("MONT_CVBA_CCHN"));
 coursChange.setMontCvbcCchn(result.getFloat("MONT_CVBC_CCHN"));

 coursChange.setDatJourCchn(result.getDate("DAT_JOUR_CCHN"));
 coursChange.setTimeCchn(result.getString("TIME_CCHN"));



 return coursChange;


 }

 }

Solution

  • Finally I got the solution ; it's so simple

    First at all : I should put the annotation @Autowired before private JdbcTemplate jdbcTemplate; to be able to use it :)

    1)

    @Autowired
    private JdbcTemplate jdbcTemplate;
    

    Second this is the correct code to recuperate data :)

    2)

    public List<CoursChange> listeCours(Date datJourCchn) {
    
    
    
        SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
        try {
            datJourCchn =sdf.parse("17042016");
        } catch (ParseException e) {
    
            e.printStackTrace();
        }
        System.out.println("debut");
    
        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=?";
    
    
    
             List<CoursChange> coursChanges = jdbcTemplate.query(sql,
                new Object[] { datJourCchn }, new RowMapper<CoursChange>() {
    
                 @Override
                    public CoursChange mapRow(ResultSet result, int rowNum)
                            throws SQLException {
    
                        System.out.println("debut Mapper 22222");
    
                        CoursChange coursChange = new CoursChange();
                        Devise devise = new Devise();
                        coursChange.setIdCoursChange(result
                                .getInt("ID_COURS_CHANGE"));
                        coursChange.setCodEtatCchn(result
                                .getString("COD_ETAT_CCHN"));
                        coursChange.setMontCabaCchn(result
                                .getFloat("MONT_CABA_CCHN"));
                        coursChange.setMontCabcCchn(result
                                .getFloat("MONT_CABC_CCHN"));
                        coursChange.setMontCvbaCchn(result
                                .getFloat("MONT_CVBA_CCHN"));
                        coursChange.setMontCvbcCchn(result
                                .getFloat("MONT_CVBC_CCHN"));
                        coursChange.setDatJourCchn(result
                                .getDate("DAT_JOUR_CCHN"));
                        coursChange.setTimeCchn(result.getString("TIME_CCHN"));
                        devise.setLibDevDev(result.getString("LIB_DEV_DEV"));
                        devise.setLibSiglDev(result.getString("LIB_SIGL_DEV"));
                        coursChange.setDevise(devise);
                        System.out.println("Fin Mapper");
                        System.out.println("coursChange jdbcTemplate" + coursChange);
                        return coursChange;
                    }
                });
        System.out.println("Fin");
        return coursChanges;
    
    }