使用Spring获取对DB2的查询的Null结果

时间:2014-06-11 06:34:47

标签: java database spring-mvc null db2

如果我通过Quantum DB运行查询,我会得到所需的结果。但是当代码中使用相同的查询时,不会抛出错误,也没有结果。

查询:

final String RECORD_LIST_QUERY = "SELECT COUNT(*) FROM A.abc AS WEU WHERE WEU.ZZAA_AUFT_NR = '?'";

final String FZEG_NR_QUERY="SELECT WEU.FZEG_NR, WEU.ZZAA_AUFT_NR FROM A.abc AS WEU WHERE WEU.ZZAA_AUFT_NR = '?'";

方法:

public OrderDetailsDto FetchOrderData(OrderDetailsDto orderDetailsDto) {
    System.out.println("DAO:through DTO: Order Nr before running query " + orderDetailsDto.getOrderNr());

    Object args = orderDetailsDto.getOrderNr();

    OrderDetailsDto orderDetailsDtoCopy = new OrderDetailsDto();

    System.out.println("Data source is " + getDataSource());
    try {
        List<Map<String, Object>> result = getJdbcTemplate().queryForList(IOrderDao.FZEG_NR_QUERY, args);
        if (result.listIterator().hasNext()) {
            System.out.println("DAO:through DTO: Order Nr before running query " + args);
            System.out.println("Result to check query is fired " + result.get(result.listIterator().nextIndex()));
        } else {
            System.out.println("DAO:through DTO: Order Nr before running query " + args);
            int cnt = getJdbcTemplate().queryForInt(IOrderDao.RECORD_LIST_QUERY, args);
            System.out.println("count of record is " + cnt);
        }
        for (Map<String, Object> record : result) {
            System.out.println("In Dao FOR Loop");
            orderDetailsDtoCopy.setOrderNr("" + record.get("ZZAA_AUFT_NR"));
            orderDetailsDtoCopy.setFZEGNr("" + record.get("FZEG_NR"));

        }

        System.out.println("In dao order number is set as " + orderDetailsDtoCopy.getOrderNr());
        System.out.println("In dao FZEG number is set as " + orderDetailsDtoCopy.getFZEGNr());
    } catch (DataAccessException e) {
        e.printStackTrace();
    } 

    return orderDetailsDtoCopy;
}

输出:

Executing D:\Users\rpashank\Documents\GOorderInfo\dist\run388364612\GOorderInfo.jar using platform C:\Program Files\Java\jdk1.7.0_51\jre/bin/java
Jun 11, 2014 11:49:54 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@367dd4d9: startup date [Wed Jun 11 11:49:54 IST 2014]; root of context hierarchy
Jun 11, 2014 11:49:54 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [D:\Users\rpashank\Documents\GOorderInfo\src\main\resources\spring-config.xml]
Jun 11, 2014 11:49:54 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@690d76d5: defining beans [dataSource,jdbcTemplate,transactionManager,transactionTemplate,orderService,orderDao]; root of factory hierarchy
Jun 11, 2014 11:49:54 AM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: com.ibm.db2.jcc.DB2Driver
OrderController orderNr before calling query 0729100528
Jun 11, 2014 11:49:54 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@40da178f: startup date [Wed Jun 11 11:49:54 IST 2014]; root of context hierarchy
Jun 11, 2014 11:49:54 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [D:\Users\rpashank\Documents\GOorderInfo\src\main\resources\spring-config.xml]
Jun 11, 2014 11:49:54 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@162292fd: defining beans [dataSource,jdbcTemplate,transactionManager,transactionTemplate,orderService,orderDao]; root of factory hierarchy
Jun 11, 2014 11:49:54 AM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: com.ibm.db2.jcc.DB2Driver
DAO:through DTO: Order Nr before running query 0729100528
Data source is org.springframework.jdbc.datasource.DriverManagerDataSource@997f31b
DAO:through DTO: Order Nr before running query 0729100528
count of record is 0
In dao order number is set as null
In dao FZEG number is set as null
Order Controller ORDER Nr. through DTO after query null
OrderController FZEG through DTO after query  null

0 个答案:

没有答案