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 :
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?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 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




Reply With Quote
