Daniel,
On 6/19/24 11:40, Daniel Schwartz wrote:
Dear Felix,
Thank you for your reply. The connector jar file is at
C:\Program Files\apache-tomcat-10.1.24\lib\mysql-connector-j-8.4.0.jar
The latest entry in catalina.2024-06-17.log is copied below. The latest entry
in localhost.2024-06-17.log is copied after that. The two entries are
essentially identical.
The cause of the failure is reported as
Caused by: java.lang.NullPointerException: Cannot invoke
"javax.sql.DataSource.getConnection()" because "this.dataSource" is null
at
com.worldholidaysandevents.restjsonwebservice.HolidaysRestJsonWebServiceResource.getJsonCountries(HolidaysRestJsonWebServiceResource.java:56)
However, this is turn is caused by the failure reported in my previous email on
the line
dataSource = (DataSource) ctx.lookup("jdbc/holidays");
in a file called DataSourceSingleton.java, which is invoked by the
getJsonCountries method. The method is supposed to extract a list of countries
from the database, but the list is returned as null since the JNDI lookup
fails. I identified this failure by putting print statements immediately
before and after this line. The statement before the line outputs its message,
and the one after this line does not. You can see this in the Command Prompt
where Tomcat is running. I copied this error message in my previous email.
Your code looks fine. Fully-specifying the JNDI URL is basically
optional, but it wouldn't hurt.
I would move that context.xml file into your application under
META-INF/context.xml and restore the original conf/context.xml because
you do not need that JNDI resource to be made available to every
application on your server (right?).
I would also recommend NOT using the "root" user for your database
connection. I realize that you are probably "just getting started" but
it would be best to use an application-specific user for your database,
and to get into that habit as soon as possible.
----------------------------------------------------------------------------------------------------------
catalina.2024-06-17.log:
-----------------------
17-Jun-2024 15:43:06.184 SEVERE [http-nio-8080-exec-1]
org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse Error while
closing the output stream in order to commit response.
org.glassfish.jersey.server.ContainerException: java.util.concurrent.ExecutionException:
java.lang.NullPointerException: Cannot invoke "javax.sql.DataSource.getConnection()"
because "this.dataSource" is null
Are there any other errors you can see in any log file?
Usually, Tomcat will emit an error if the JNDI resource cannot be created.
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org