CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 38

Threaded View

  1. #1
    Join Date
    Sep 2009
    Posts
    24

    How can I Initialize getJdbcTemplate()?

    Task- Just need to select table data (one column also ok) from table1 and return as java.util.List

    ------------------------------
    integration-dao.xml
    -----------------------------

    Code:
    <bean id="cListDAO "
    class="com…..CListDAO "
    p:dataSource-ref="dataSource" 
    p:sqlLoader-ref="sqlLoader" /> 
    
    
    <bean id="sqlLoader"
    class="com.asi.integration.common.business.dao.sql .SQLLoader" />
    -------------------------
    integration-datasource.xml
    -------------------------
    Code:
    <bean id="dataSource"
    class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close"
    p:driverClass="${my.jdbc.driverClassName}"
    p:jdbcUrl="${my.jdbc.url}"
    p:user="${my.jdbc.username}"
    password="${my.jdbc.password}"
    p:initialPoolSize="${my.jdbc.pool.init.size}"
    p:maxPoolSize="${my.jdbc.pool.max.size}"
    preferredTestQuery="${my.jdbc.preferredTestQuery }"
    p:idleConnectionTestPeriod="${my.jdbc.idleConnecti onTestPeriod}"/>
    -------------------------------
    integration-hibernate.xml
    --------------------------------
    Code:
    <!-- Hibernate SessionFactory for datasource -->
    <bean id="mySessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean"
    p:dataSource-ref="dataSource">
    
    <!-- tried by giving this also--><!--<property name="dataSource" ref="dataSource"></property> --> 
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    ${my.hibernate.dialect}
    </prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.max_fetch_depth">3</prop>
    <prop key="hibernate.query.substitutions">
    true 1, false 0
    </prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    </props>
    </property> 
    </bean>
    -------------------------
    SQLConstants.java
    -------------------------
    Code:
    public class SQLConstants {
    public static final String PACKAGE = ClassUtils.getPackageName(SQLConstants.class);
    public static final String C_NUMBERS_LIST =
    "CNumberList.sql";
    
    /**
    * Private constructor to prevent instantiation.
    */
    private SQLConstants() {
    super();
    }
    }
    -------------------------
    CNumberList.sql
    ----------------------
    Code:
     select * FROM table1

    ----------------------------
    CListDAO.java
    -----------------------
    Code:
    public class CListDAO extends JdbcDAO { 
    
    
    public List claims() {
    
    
    List li = getJdbcTemplate().queryForList(
    this.loadQuery(SQLConstants.PACKAGE, 
    SQLConstants.C_NUMBERS_LIST));
    
    Iterator iter = li.iterator(); 
    System.out.println("I want ===>>"+li.size());
    while(iter.hasNext()){
    System.out.println("I want->>>>"+iter.next());
    }
    
    return li; 
    }
    --------------------------
    JdbcDAO.java
    ----------------------------------
    Code:
    public class JdbcDAO extends JdbcDaoSupport implements IJdbcDAO {
    private SQLLoader _sqlLoader;
    
    ….
    
    protected String loadQuery(String packageName, String sqlName) {
    return _sqlLoader.loadQuery(packageName, sqlName);
    }
    ….
    }
    ----------------------------------------


    I am getting NullPointerException at
    Code:
     “ getJdbcTemplate().queryForList(
    this.loadQuery(SQLConstants.PACKAGE, 
    SQLConstants.C_NUMBERS_LIST));
    , I observed getJdbcTemplate() Is comming as null.

    How can i create instance of JdbcTemplate here ?
    Do I need to use sessionfactory , if yes , how can I wire up ?

    Please tell me what I missed above.

    Thanks in advance.

    ==========================
    Error:
    ===========================
    Code:
     java.lang.NullPointerException
    at com…….CListDAO.getRecords(ClaimsListDAO.java:32)
    at com……..runScheduledJob(GenerationScheduledJob.java :52)
    at com….common.jobs.AbstractScheduledJob.execute(Abst ractScheduledJob.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.springframework.util.MethodInvoker.invoke(Meth odInvoker.java:276)
    at org.springframework.scheduling.quartz.MethodInvoki ngJobDetailFactoryBean$MethodInvokingJob.executeIn ternal(MethodInvokingJobDetailFactoryBean.java:260 )
    at org.springframework.scheduling.quartz.QuartzJobBea n.execute(QuartzJobBean.java:86)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:2 02)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run (SimpleThreadPool.java:529)
    Last edited by java_dev; September 14th, 2009 at 02:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured