Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"

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
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by tangara goh


I am trying to use CDI using Weld in my web App using Java servlet with Tomcat or possibly change to TOMEE.

However, I am confused as to what are the dependencies I needed.

Right now, I have :

<!-- -->

I would like to know if I need to install javaee-api or javaee-web-api on top of what I have.


Dave Tolls wrote:Well, I used 'name' since I was guessing you might be sending the subject name (which I would assume was unique).
You could always send a subject id.  That's up to you.

For the IN, the most secure way is to build the list of '?' placeholders and the do a load of setString (or setInt if using ids) on the PreparedStatement.

The initial answer on this SO thread is the usual way to build up the IN, using String.join and's a lot easier than it used to be!

Hi Dave,

I am writing to you again cos I need more explanation regarding the stackoverflow reference.
The thing is I have problem in understanding the methods explained there. The thing that puzzled me most is the Select sql statement.
Why use select if the data is not inserted in as yet?

The thing is that I am going to insert the List<String> together with other strings like tutorName, email etc into the table Tutor so it is not inserted yet and so why use Select ?

Hope you can explain to me.


16 hours ago

I am trying to insert List<String> together with other variables into MYSQL, as now i am facing the problem in the insertion to make it into different rows. Can this be done? or Am I making my life too difficult this way?

There is this method shown by A Kunin which I hope to understand what he is trying to say; as I am quite lost what he is trying to do.


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(
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(

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).


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 ;

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.


2 weeks 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.

   <Console name="Console" target="SYSTEM_OUT">
     <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    <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.


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....