Le serveur arencontréuneerreur interne qui l'aampêchédesatisfairelarequête

时间:2016-04-23 12:56:47

标签: spring jdbctemplate

我第一次在Spring中使用JdbcTemplate;

我想从数据库中恢复数据;我不知道我的错误是什么;

请帮我解决这个问题,并提供一个有用的课程,以便在春天使用JdbcTemplate;

这是我的代码:

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;


 }

 }

1 个答案:

答案 0 :(得分:0)

最后我得到了解决方案;它很简单

首先:我应该在私有JdbcTemplate jdbcTemplate之前放置注释@Autowired;能够使用它:)

1)

@Autowired
private JdbcTemplate jdbcTemplate;

其次,这是恢复数据的正确代码:)

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;

}