How can I Initialize getJdbcTemplate()? - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 38

Thread: How can I Initialize getJdbcTemplate()?

  1. #16
    Join Date
    Sep 2009
    Posts
    24

    Re: How can I Initialize getJdbcTemplate()?

    Hi Deliverance, I am facing one issue, I injected FieldValue in spring config file as follows,

    x-shedular.xml

    Code:
    <bean id="fieldValue" class="com….FieldValue"/> 
    
    <bean id="activityGenerationJob"
    		class="com….CActivityGenerationScheduledJob"
    		  p:fieldValue-ref="fieldValue" 
    		/>
    CActivityGenerationScheduledJob.java
    Code:
    When I tired to override two columns  
    fieldValue[0].setIdentifier("0");  
    fieldValue[0].setName("FirstDate");
    fieldValue[0].setValue(updated_FirstDate);
    
    fieldValue[0].setIdentifier("1");  
    fieldValue[0].setName("SecondDate");
    fieldValue[0].setValue(updated_ SecondDate);
    
    cAPIClient.addActivityWithOverride(somenumber, “some value”,fieldValue);
    HTML Code:
    Constructor Summary 
    1. FieldValue() 
    2. FieldValue(java.lang.String identifier, java.lang.String name, java.lang.String value)
    I can't set size as bellow , becose it is a final value

    Code:
    if(fieldValue.length ==0){
     fieldValue.length = 5;
    }
    addActivityWithOverride() method 3 parameter is type of FieldValue, When I tried with HashMap, type cast exception is comming.

    but my first name and value is overriding/replacing by second value, here how can I initialize the FieldValue with value more than 1 so that I can generate Activity With Override.

    Please help.
    Last edited by java_dev; September 29th, 2009 at 05:58 AM.

  2. #17
    Join Date
    Apr 2007
    Posts
    425

    Re: How can I Initialize getJdbcTemplate()?

    And with good reason.

    length is a property that primitive array types provide, as a convenience for polling the size of the array. It can only be read from.

    Code:
    FieldValue [] fieldValues = new FieldValue[5];
    System.out.println(fieldValues.length);
    ------
    If you are satisfied with the responses, add to the user's rep!

  3. #18
    Join Date
    Sep 2009
    Posts
    24

    Re: How can I Initialize getJdbcTemplate()?

    Deliverance, When I initialized as
    try1: with out removing FieldValue bean injection in config file

    Code:
    fieldValue = new FieldValue[5];
    try2: after removing FieldValue bean injection in config file

    Code:
    FieldValue fieldValue = new FieldValue[5];

    For Both tries, I am getting null pointer exception at

    Code:
    fieldValue[0].setIdentifier("0");
    please help.

  4. #19
    Join Date
    Sep 2009
    Posts
    24

    Post Re: How can I Initialize getJdbcTemplate()?

    Code:
    And with good reason.
    
    length is a property that primitive array types provide, as a convenience for polling the size of the array. It can only be read from. 
    
    
    Code:
    FieldValue [] fieldValues = new FieldValue[5];
    System.out.println(fieldValues.length);
    here spring is injecting the FieldValue bean, do we need new keyword again ? all I want is how to assign size. please correct me if am wrong.

  5. #20
    Join Date
    Apr 2007
    Posts
    425

    Re: How can I Initialize getJdbcTemplate()?

    In the constructor, or @PostConstruct annotation you should provide initialization of this array. This assumes you know the size you need in advance, and it is fixed.
    You have only provided a container to hold these objects, but it does not contain the reference objects yet, so you still have to do

    Code:
    fieldValues[0] = new FieldValue();
    ------
    If you are satisfied with the responses, add to the user's rep!

  6. #21
    Join Date
    Sep 2009
    Posts
    24

    Re: How can I Initialize getJdbcTemplate()?

    When I initialized with 5 as bellow

    Code:
    fieldValue[5] = new FieldValue();
    I am getting

    Code:
     java.lang.ArrayIndexOutOfBoundsException: 5
    how to resolve this?

  7. #22
    Join Date
    May 2009
    Location
    Surrey, UK
    Posts
    285

    Re: How can I Initialize getJdbcTemplate()?

    --
    Last edited by jcaccia; September 29th, 2009 at 10:22 AM.

  8. #23
    Join Date
    Apr 2007
    Posts
    425

    Re: How can I Initialize getJdbcTemplate()?

    Quote Originally Posted by jcaccia View Post
    new FieldValue() creates one instance of FieldValue. At the left of the assignment operator you have an array of 5 objects of type FieldValue.
    Incorrect.

    Left hand side is fieldValues at index 5 , which is out of range, since arrays start at 0.

    you have 0, 1, 2, 3, 4 (which is 5 elements).
    ------
    If you are satisfied with the responses, add to the user's rep!

  9. #24
    Join Date
    May 2009
    Location
    Surrey, UK
    Posts
    285

    Re: How can I Initialize getJdbcTemplate()?

    You are right, sorry, got distracted in the office while replying to the post and ended writing that stupid reply...

  10. #25
    Join Date
    Sep 2009
    Posts
    24

    Re: How can I Initialize getJdbcTemplate()?

    Hi jcaccia and Deliverance, thanks for you concerns on my issue.

    Can you please let me know how can I solve my above issue? I am struck....

    Thanks in advance!

    -Dev

  11. #26
    Join Date
    Apr 2007
    Posts
    425

    Re: How can I Initialize getJdbcTemplate()?

    Quote Originally Posted by Deliverance View Post

    Left hand side is fieldValues at index 5 , which is out of range, since arrays start at 0.

    you have 0, 1, 2, 3, 4 (which is 5 elements).
    ^ that answers it.
    ------
    If you are satisfied with the responses, add to the user's rep!

  12. #27
    Join Date
    Sep 2009
    Posts
    24

    Re: How can I Initialize getJdbcTemplate()?

    I want to initialize to more than one so that I can append two columns to override (please refer my #16 post)

    When I tried as follows
    Code:
    fieldValue[0] = new FieldValue();
    I am getting following exception at

    Code:
    fieldValue[1].setName("SecondDate");
    fieldValue[1].setValue(updated_ SecondDate);
    Exception:
    Code:
     java.lang.ArrayIndexOutOfBoundsException: 1
    Please help.

  13. #28
    Join Date
    Apr 2007
    Posts
    425

    Re: How can I Initialize getJdbcTemplate()?

    Refer to my post #20.

    The array capacity has to be instantiated or given to you (assuming you know this in advance).

    Is this your implementation of the class? Can you switch this to LinkedList<FieldValue> instead that is wired to you? It's unclear what you are doing or plan to do , but an array class that has to be dynamically created for me isn't an ideal candidate to be wired up by Spring.

    You have two things you must do:

    1) Instantiate the array
    2) Instantiate the objects, and provide the reference object to the desired index.

    It's hard to give you more info without knowing what/why you are doing it this way, and whether or not you manage the code behind FieldValue.
    ------
    If you are satisfied with the responses, add to the user's rep!

  14. #29
    Join Date
    Sep 2009
    Posts
    24

    Thumbs up Re: How can I Initialize getJdbcTemplate()?

    Excelent Deliverance, I am able to resolve with your above inputs. Thanks

  15. #30
    Join Date
    Sep 2009
    Posts
    24

    Re: How can I Initialize getJdbcTemplate()?

    Hi,

    I want to write JUnit test cases for my job.

    CActivityGenerationScheduledJob.java

    Code:
    public void setICListDAO(ICNumberListDAO cListDAO) {
    	this.cListDAO = cListDAO;
    }
    
    public void runScheduledJob() {		 
      List result_list = cListDAO.getAllCPublicIDs();
      .
      .
      .
    }
    ICNumberListDAO.java

    Code:
    public interface ICNumberListDAO extends IJdbcDAO {
    	List getAllCPublicIDs();
    	// other methods
    }
    CCCListDAO.java

    Code:
    public class CCCListDAO extends JdbcDAO implements ICNumberListDAO {
    
    	public List getAllCPublicIDs() {
    		List result_list=null ;
    		try{
    		 result_list = getJdbcTemplate().queryForList(
    				this.loadQuery(SQLConstants.PACKAGE,
    						SQLConstants.C_LIST));
    		
    		} catch (Exception bse) {
    			logError("Error in querying.", bse);
    		} 
    		return result_list;
    		
    	}
    }
    CActivityGenerationScheduledJobTestCase.java
    Code:
    public class CActivityGenerationScheduledJobTestCase extends
    		AbstractTestCase {
    public void testRunScheduledJob() {
       cActivityGenerationScheduledJob.setICListDAO(cListDAO);
       cActivityGenerationScheduledJob.setICAPIClient(iCAPIClient);
    	try {			
    	cActivityGenerationScheduledJob.runScheduledJob();
    
    		} catch (Exception e) {
    			logError("Error running runScheduledJob.", e);
    			fail();
    		}
    	}

    when I called runScheduledJob() from CActivityGenerationScheduledJobTestCase class I am getting following exception. Please tell me the best solution for this.

    (I have observed CCCListDAO class is coming as null)


    Error:
    HTML Code:
    2009-10-26 06:21:58,772 ERROR Error in Generating   Activity.
    java.lang.NullPointerException
    	at com……CActivityGenerationScheduledJob.runScheduledJob(CActivityGenerationScheduledJob.java:61)
    	at com……CActivityGenerationScheduledJobTestCase.testRunScheduledJob(CActivityGenerationScheduledJobTestCase.java:44)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:324)
    	at junit.framework.TestCase.runTest(TestCase.java:164)
    	at junit.framework.TestCase.runBare(TestCase.java:130)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:120)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

    - Dev

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center