Context information in Tomcat5.5

I am facing this peculiar problem. My webapp, works fine on my localhost. Its a JSP/Struts-Tomcat-MySQL app. However, when I host it on hostjava.net (shared tomcat), it is unable to connect to the database.

After some debugging, I have identified the problem, to be with JNDI lookup for datasource. If you want, you can take a look at the log at http://rohitesh.hostjava.net/MapsDummyLog.htm

Some details on the context information location : /META-INF/context.xml contains :

<Context path="" docBase="" debug="5" reloadable="true" crossContext="true" override="true">
   <Resource name="jdbc/ConnectionPooling" auth="Container" type="javax.sql.DataSource"
    maxActive="10" maxIdle="5" username="[username]" password="[password]" driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost/[db name]?autoReconnect=true" />
</Context>

Can anyone help me find out, where am going wrong, please?

Cheers, Rohitesh.


Asked by: Patrick195 | Posted: 23-01-2022






Answer 1

Shouldn't this:

url="jdbc:mysql://localhost/[db name]?autoReconnect=true"

really point at the name of the server on which the database is hosted? On th remote host the database server may not be the same machine as the tomcat instance. I would think that you have to say

url="jdbc:mysql://[Server_Name]/[db name]?autoReconnect=true"

Answered by: Ada390 | Posted: 24-02-2022



Answer 2

Here goes my guess:

You said it's a shared hosting. Then shouldn't

<Context path="" 

contain the context path of your particular application?

http://tomcat.apache.org/tomcat-5.5-doc/config/context.html The context path of this web application, which is matched against the beginning of each request URI to select the appropriate web application for processing. All of the context paths within a particular Host must be unique. If you specify a context path of an empty string (""), you are defining the default web application for this Host, which will process all requests not assigned to other Contexts.

So you context is invalid and, I presume, simply invisible (that's why null driver and null url).

It would work on your local as "" is a shared context for all apps deployed, including yours.

Answered by: Patrick250 | Posted: 24-02-2022



Answer 3

How about this restriction:

http://wiki.hostjava.net/index.php/HostJava.net_FAQ With Shared Tomcat access to server.xml file is restricted. Only support staff can add Realm (for example JDBC Realm)to server.xml file.

Looks like you need to ask support to add your datasource.

Answered by: Kimberly583 | Posted: 24-02-2022



Answer 4

Rohitesh,

Per Vladimir's answer and comments, you may want to consider requesting the server context (server.xml, or the more globally scoped context.xml) be updated.

If nothing else, this is, in my opinion, a best practice. While Tomcat does allow you to define the context (including JNDI resources) from within the web application itself, the only place you should use this feature is in a developer's local test server. It makes your web application more portable, as it allows to change the configuration of your external resources (in this case, the database, but it could be a mail server, or content server, rules engine etc) independently of your application.

I hope this helps.

Answered by: William625 | Posted: 24-02-2022



Answer 5

"java.lang.NullPointerException at com.DAO.UserDAO.userLogin(UserDAO.java:109) at com.Actions.UserAction.execute(UserAction.java:66) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) "

This tells me that something is NOT being initialized properly. on what object are you invoking in line 109 of UserDAO.java ?

"10/25/08 (2:08 AM) ajp-127.0.0.1-8015-1 ERROR UserDAO.java:104 Cannot create JDBC driver of class '' for connect URL 'null'
10/25/08 (2:08 AM) ajp-127.0.0.1-8015-1 ERROR UserDAO.java:105 org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' "

Did you check the URL for the DB. it appears that the URL is invalid or NULL. Can you give a manual value for the JDBC connection URL ?

Answered by: Miller831 | Posted: 24-02-2022



Answer 6

The peculiar thing is, that another part of the same application, accesses the database, with a hardcoded url (using DriverManager, and NOT datasource from the JNDI lookup), and that works just fine (check out the first two lines in the log, and the next couple of lines with cuisine names, which are read from the database). So, it is certain, that the database is also on the same server.

Cheers, R

Answered by: Michelle623 | Posted: 24-02-2022



Answer 7

  • is the driver available? Try Class.forName("com.mysql.jdbc.Driver"); - and it can't be located in your webapps WEB-INF/lib because you are asking for the container (tomcat) to instantiate it for you: It needs to be in the servers classpath
  • Are you running Tomcat 5.5.x or 6.0.x? On 5.0.x the context.xml syntax, especially resource definition, has been different: Way more xml tags instead of the nicer and simpler attributes since 5.5.

Answered by: Jack152 | Posted: 24-02-2022



Answer 8

Another note: Do you have access to any other log files besides the one you posted? If you have access to the server logs/catalina.out file, it may show you the exact problem Tomcat is having setting up the data source (this would be right when you start up Tomcat).

Answered by: Adelaide798 | Posted: 24-02-2022



Answer 9

Sorry everyone. It was a problem of miscommunication between me and the Support team of the hosting facility. There was a clash of configs. They had set some old settings in server.xml. As that takes precedence over any other context information, I was facing those issues. Now it is taken care of.

But I still feel, that to allow people on a shared configuration, to have their context information in META-INF/context.xml file, is a better option. That way, they have more control over it.

But I Thank everyone, who took the time out, to respond. I learnt a lot from you. Thank you again.

Cheers, R

Answered by: John919 | Posted: 24-02-2022



Similar questions

tomcat5.5 - Moving From Java1.5 to Java 1.6?

I'm currently running my web application on Java1.5 codebase, running it on Tomcat 5.5 and MySql 5. Looking through the list of additions that were added into Java1.6, I have to ask the question, "Is there any compelling reason to move from 1.5 to 1.6?". There seems like an incredible lack of necessary improvements and additions. A lot of changes in Swing (not that interesting). Keep in mind the current web application...


java - How to upload a file in Tomcat5.5?

I want to do the following in tomcat 5.5 1. upload a excel file 2. process the file based on some crieteria 3. show the result I am able to do all from 2 to 3 but not able to upload a file in tomcat 5.5 and could not also find example. Pleaes help me.






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top