Struts & Mysql - can't get to server.xml must put in struts-config
Posted by: wes
Date: March 06, 2005 01:14AM

Hello all. I've developed a Struts application and used the JNDI data source in the server.xml file. I've deployed it to the host and it's been working great. I have a virtual Tomcat installation that I have access to the server.xml file so I created the datasource in the Container.

I've had to switch hosts and although I still have a virtual Tomcat installation where I can restart the server. The problem now is that I cannot have access to the server.xml file. I'm now stuck having to configure it in the struts-config.xml file and I am not sure how to go about this. I know the ideal way is to do this in the Tomcat server.xml file but since they won't let me do that, I have to change my web app. I've been using a DAO installation but I think with the datasource being in the struts-config.xml file I have to have a request to get the datasource?

I've been doing this in a getConnection(String dbName) method with it getting it's DataSource object like this:

Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/" + dbName);

Then I can get the Connection and return it.

The problem now is that I don't think I can get the ds in the same way. It's a matter of changing one class - thank you, DAO, but I'm not sure how to set this up.

I'm in need of getting this up and running soon. Anyone able to help me? I was doing great learning Struts, Tomcat, etc. all at once, but now I'm stuck. I know it's not ideal to use anything but the server.xml file (JNDI?) to configure the DataSource, but I'm stuck with it.

I've got to use connection pooling, obviously, but I'm not sure how to set this up. I can model the <data-source> in struts-config.xml for the struts-blank WAR, but I'm not totally sure what to use for the <data-source type=??> I've got the driverClassName (com.mysql.jdbc.Driver) and the url: "jdbc:mysql://localhost/databaseName"

My question would be:

1) What should the <data-source type...> be?

2) How do I change the method of getConnection() to use this datasource

3) Is there anything else I could/should be doing?

All the examples I've seen use the server.xml - JNDI solution. I'm having a heck of a time trying to find an example using the struts-config.xml file to set this up. I'm assuming I'll need an entry in the web.xml file too?

Sorry, I'm still kinda new to all this. So many places to look - struts, tomcat, mysql... It's all confusing at this point and not being able to find some examples is making it worse. Anyone able to help? I'd truly appreciate it!


Options: ReplyQuote

Written By
Struts & Mysql - can't get to server.xml must put in struts-config
March 06, 2005 01:14AM
March 30, 2005 06:26AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.