• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

How can I set the parameter in this case?  RSS feed

 
Ranch Hand
Posts: 468
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying very hard till the extend now that I think maybe it can't be done by Java EE after all.  So, I would like to confirm my doubt.
And if it can be done, I hope someone can tell me what is wrong with the way I do it.

Here's the snippet of code in my Controller - a servlet where I need to set the Parameters for subjects.



At my class tutor :



At my class - tutorImpl, I tried to call from the Controller's setter this way:




I really hope someone can point out my mistakes cos I am beginning to think that it can't be done by Java EE and may be I need dependency injection (Pardon me...I just plug something like that cos I am not sure).

Tks!
 
Saloon Keeper
Posts: 5132
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What specific problem are you facing with this code? What does or does not work according to your expectations?
 
tangara goh
Ranch Hand
Posts: 468
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:What specific problem are you facing with this code? What does or does not work according to your expectations?



The problem is that when the debugger tried to read in the value, it is returning null.

I have put in the problems under //
 
Tim Moores
Saloon Keeper
Posts: 5132
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

// m4.setSubject(subject); //setSubject() returned null


What kind of object is m4? You posted an excerpt of a class that does not have a setSubject method (or a setSubjectNames method, for that matter), so we can't say anything.
 
tangara goh
Ranch Hand
Posts: 468
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:

// m4.setSubject(subject); //setSubject() returned null


What kind of object is m4? You posted an excerpt of a class that does not have a setSubject method (or a setSubjectNames method, for that matter), so we can't say anything.



Sorry, It should be tutor m4 = new tutor() in the servlet code.

I have tried the below setSubject method in tutor Class but it is not working

 
Tim Moores
Saloon Keeper
Posts: 5132
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain what "it doesn't work" means - in detail.

Also, the setSubject method doesn't do anything. Surely it should set a value?
 
tangara goh
Ranch Hand
Posts: 468
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Please explain what "it doesn't work" means - in detail.

Also, the setSubject method doesn't do anything. Surely it should set a value?



As mentioned, the // described the error.
//setSubject() returned null

What I wanted to do is like the rest of the parameters where I do the set, I can get the value at the tutorDAOImpl.

But, for this case, even though the String[]subj is transformed as an ArrayList, I can't set the subjects to the tutor which in this case is the new object - m4.



Hope that I am clear in my explanation about the part that doesn't work.

So, my question is how should I write the setter in the tutor class to make this m4.setSubjects or set the List<String>subjects to tutor works ?

 
Tim Moores
Saloon Keeper
Posts: 5132
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only method that sets "subj" -which is what the setSubject returns- is "setSubj" - is that ever called? It's hugely confusing to have both setSubj and setSubject methods - you should have only one method, and that should set the value (like setSubj does). I don't see why it needs to return the value it has just set - the calling code already knows which value it has.

Also, class names in Java start with uppercase letters - the class should be called Tutor, not tutor.
 
tangara goh
Ranch Hand
Posts: 468
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:The only method that sets "subj" -which is what the setSubject returns- is "setSubj" - is that ever called? It's hugely confusing to have both setSubj and setSubject methods - you should have only one method, and that should set the value (like setSubj does). I don't see why it needs to return the value it has just set - the calling code already knows which value it has.

Also, class names in Java start with uppercase letters - the class should be called Tutor, not tutor.




Hi Tim,

I am confused myself here, due to my poor programming skill.....

I have changed the method to below :  Do you think it's ok ?


But, now I get another error :


nulljava.sql.SQLException: No value specified for parameter 10
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)



It seems there is something wrong with the code at tutorImpl :


When the debugger jumped to this part, it just said there is no parameter set for parameter 10. What is wrong here?

I am confused about this part as well, cos I need to iterate over a List and I hope you can point out my mistakes cos I am using for loop and I am not sure if the compiler will know if m.getSubjects() need to repeat according to the size of subNames.

 
Tim Moores
Saloon Keeper
Posts: 5132
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes sense: subNames is empty, so line 15 is never executed.

But even if subNames was not empty it wouldn't make sense, because you'd be setting item #10 multiple times, each time with the same data ("m.getSubjects()").
 
What's brown and sticky? ... a stick. Or a tiny ad.
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!