속성 파일에있는 SQL 쿼리에 값 목록을 전달하면서 문제가 발생했습니다. 어쨌든 내가 자리 표시자를 동적으로 생성 할 수 있습니까? 받은 값에 따라 그렇다면 정적 쿼리가 작동합니까? 제발 조언.Spring JDBC 템플릿 쿼리
DAO 코드 :
public List<DestinationDTO> fetchEmsStatistics(DestinationDTO destinationDTO)
//throws Exception
{
LOG.info("start of -- MonitorDAOImpl.fetchEmsStatistics()");
List<DestinationDTO> destinationDTOList = new ArrayList<DestinationDTO>();
String str = destinationDTO.getDestinationNames();
String dest[] = str.split(",");
/* "example 1" , "example2" are hardcoded,however i want the values of dest array and according to count the placeholders should be placed in the query */
try{
destinationDTOList = this.jdbcTemplate.query(
this.fetchEmsStatisticsQuery,
new Object[] {
"%" + destinationDTO.getDestinationTypeId() + "%",
destinationDTO.getDestinationSourceId(),
"example1","example2",
destinationDTO.getStartTime() + ":00",
destinationDTO.getEndTime() + ":00" },new DestinationDTORowMapper());
System.out.println("finally"+ destinationDTOList.size());
}
catch(Exception e)
{
e.printStackTrace();
}
LOG.info("end of -- MonitorDAOImpl.fetchEmsStatistics()");
return destinationDTOList;
}
검색어 :
Select
DESTINATION
,MIN_IC
, MAX_IC
,MAX_OC
,MAX_IC-MIN_IC as PROCESSEDMSGS
from (
select
DESTINATION
,min(IN_MSG_COUNT) MIN_IC
,max(IN_MSG_COUNT) MAX_IC
, max(OUT_MSG_COUNT) MAX_OC
from
EMS_MONITOR C
where
C.DESTINATION_TYPE_ID like ? and
C.SOURCE_ID=? and
C.DESTINATION IN (?,?) and
C.RCVD_DATE >=? and C.RCVD_DATE <=?
group by
DESTINATION
)
원하는 쿼리 형식 :
Select
DESTINATION
,MIN_IC
, MAX_IC
,MAX_OC
,MAX_IC-MIN_IC as PROCESSEDMSGS
from (
select
DESTINATION
,min(IN_MSG_COUNT) MIN_IC
,max(IN_MSG_COUNT) MAX_IC
, max(OUT_MSG_COUNT) MAX_OC
from
EMS_MONITOR C
where
C.DESTINATION_TYPE_ID like '%1%' and
C.SOURCE_ID=1 and
C.DESTINATION in ('M.COM.CAT.AVAIL.STORE.Q.FCC','M.COM.CAT.ELIG.BOPS.STORE.Q.FCC') and
C.RCVD_DATE >='2014-09-16 17:00:00' and
C.RCVD_DATE <='2014-09-16 20:01:00'
group by
DESTINATION
)
하나의 매개 변수 마커 - 하나의 값입니다. – mustaccio
@mustaccio 지금 코드를 변경했는데 하드 코딩 된 값으로 잘 작동하지만 하드 코딩 된 값 대신 동적 값을 배치하고 싶습니다. DAO 나 쿼리에서 속성을 변경하려면 어떻게해야합니까? (속성 파일에만 쿼리를 배치 할 수 있습니다.) 당신의 소중한 제안을하십시오. – Jalal
IN 목록에 합리적인 최대 값 수가있는 경우, 그 매개 변수 마커 수와 함께 명령문 텍스트를 저장할 수 있습니다 :'... DESTINATION IN (?,?,?,? ...,?) ...' 값이 충분하지 않으면 매개 변수에 널 (null)을 지정하십시오. 또는 아래 답변 중 하나에서 제안 된대로 동적 SQL을 사용하십시오. – mustaccio