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

Threaded View

  1. #1
    Join Date
    Dec 2011
    Posts
    7

    Why the getMethod for List<String> is not printing out the values in another Method?

    I have been dealing with this problem for the longest time and I really hope someone can tell me what's happening and how to make the getMethod for List<String> returns the values.

    Code:
    public void insertTutor_Subject(int tutor_id, List<String> subjNames) throws MyDataException {
    		
    		Tutor m = new Tutor();
    		System.out.println(tutor_id); //this will return the generated_id
    		System.out.println(m.getSubjects());//not able to print out
    try {
    			//openConnection();		
    			PreparedStatement ps3 = connection.prepareStatement("INSERT INTO project.tutor_subject(tutor_id, subjectName) VALUES (?, ?);");
    			ps3.setInt(1, tutor_id);
    			//System.out.println(m.getTutor_id()); //m.getTutor_id() will give you 0
    			ps3.setObject(2, m.getSubjects());
    			System.out.println(m.getSubjects());
    			ps3.addBatch();
    			ps3.setInt(1, tutor_id);
    			ps3.setObject(2, m.getSubjects());
    			ps3.addBatch();

    At my controller :

    Code:
    String[] subj = request.getParameterValues("subject");
    			List<String>subjs = new ArrayList<String>(Arrays.asList(subj));
    		    m4.setSubjects(subjs); 
    		    System.out.println(m4.getSubjects());	// able to see the values
    My first question is m4.getSubjects at the controller is able to return the value so why is it not showing up at the insertTutor_Subject method?

    My 2nd question is do I still need to OpenConnection(static method for JDBC Connection) in order for the insertion to work?

    My last question is if the above - using Batch to insert the List<String> ? Is there anything wrong with this method ?

    Thanks
    Last edited by 2kaud; December 26th, 2018 at 08:48 AM. Reason: Added code tags

Tags for this Thread

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