tangara goh

Ranch Hand
+ Follow
since Dec 27, 2009
I am a beginner in Java and hope to pick up the trade secrets so that I can move on to Android development
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
1
Total given
57
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by tangara goh

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 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 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 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 //
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!

Knute Snortum wrote:Do you really mean "amp&" and not "&amp"?



Sorry I meant "& without ;"


When I just used "amp&" without ; on the small test programme, it works fine.

Tim Holloway wrote:

Knute Snortum wrote:The &amp;s have turned back into just &.



Note for the confused: The JavaRanch message display system also evaluates the '&amp;' entity, so make sure when you type or copy an example to preview the output. If it's getting mangled, use the escapes to make it display as you are actually seeing it on your machine.



Hi Tim,

I have tried to put '&' and '&" but still getting the below error.

It seems like this problem cannot be resolved.  What are the alternatives for me in this case?

ERROR: Unable to Connect to Database.
16:12:51.800 [http-nio-8013-exec-3] ERROR daoMySql.tutorDAOImpl - Failed to obtain JDBC connection
java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';UseLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=False'.

I also tried with a small public static void main(String[] args) {

and when I use just & without ;, everything works ok.

So, I am really stuck and it's been so long already.

What do you suggest ?
I just come to know that it is unsafe to put your access password etc in your code, after reading the article from Heroku ;

https://devcenter.heroku.com/articles/config-vars

However, I am quite confused as to the mechanic of the way it works.

Initially, I thought the Access password should be stored in a properties file but it is wrong or it is ok to do so?

I hope someone can explain to me how to set config in environment.

Tks.





1 week ago

Knute Snortum wrote:Change all the & to &amp;



Hi Knute,

It is still giving me the same error

java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';useSSL=FALSE&logger=com.mysql.cj.jdbc.log.Slf4JLogger&profileSQL=true'.

Hi Dave,

There is indeed a log4j.xml file where I put in the required URL.

<Appenders>
   <Console name="Console" target="SYSTEM_OUT">
     <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
   </Console>
    <param name="URL" value="jdbc:mysql://localhost/project?serverTimezone=UTC&autoReconnect=true&useSSL=False;"/>
       <param name="driver" value="com.mysql.cj.jdbc.Driver" />

Should I do the URL differently; meaning the syntax is not the same in the java code ?

Please advise me how it should be in the xml.

Tks.

Hi Dave,

Basically, all my connection URL are static and I stored them in a singleton class.

So, I just use the tutorImpl to get the connection from there.

And the error points out that it comes from that URL string....

Dave Tolls wrote:Well, that one doesn't seem to match the error posted earlier.
Are you sure that ULR caused that error?



Hi Dave,

Yes.  I double check and ran the jsp again and this is exactly what I got.

Here's the URL again:






Dave Tolls wrote:That's different from the original error, so what does your connection string look like now?



Hi Dave,

Here's the latest URL value.



May I know what the error is about cos I have been trying very hard but to no avail.

I just want to add that the log4j2.xml is working fine but the old error still appears.

com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';useSSL=FALSE&logger=com.mysql.cj.jdbc.log.Slf4JLogger&profileSQL=true'.

What is the problem in this case ?