aspose file tools*
The moose likes Struts and the fly likes where to put my Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "where to put my "mysql-5.0.3-bin.jar" file" Watch "where to put my "mysql-5.0.3-bin.jar" file" New topic

where to put my "mysql-5.0.3-bin.jar" file

Sai Narasimha Reddy

Joined: Dec 13, 2006
Posts: 23
I'm using Struts 1.2.9

if i put mysql-connector-java-5.0.3-bin.jar in my "/WEB-INF/lib" directory, i'm getting ClassNotFoundError. If i put it in "$TOMCAT-DIR/common/lib" directory it's working fine.

the problem is, i don't want to depend on the tomcat's libraries......i want to include that file in my /WEB-INF/lib folder ( so that my application will be self-consistent).

Is there any other way to use connection pooling without <data-sources> mechanism in struts......i heard in this forum that it's not a recommended approach. If so what else to use to get my connections pooled.

Please reply!

Sai Narasimha
Sai Narasimha Reddy

Joined: Dec 13, 2006
Posts: 23
My data-source tag in struts-config.xml is,

<pre name="code" class="core"><data-sources>
<data-source type="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
<set-property property="url"
value="jdbc:mysql://databaseHost:3306/jobportal?autoReconnect=true" />
<set-property property="username" value="databaseUsername" />
<set-property property="password" value="databasePassword" />
<set-property property="maxActive" value="5" />
<set-property property="maxWait" value="5000" />
<set-property property="defaultAutoCommit" value="false" />
<set-property property="defaultReadOnly" value="false" />

i have seen in "D:\apache-tomcat-5.5.25\common\lib\naming-factory-dbcp.jar", that the "org.apache.tomcat.dbcp.dbcp.BasicDataSource" exists. Is that problem ( that i have to place mysql.jar in /common/lib) because of this??

do you think that problem disappears if i use commons-pooling??

why is data-source approach in struts is not recommended??
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you look closely at the documentation for Struts 1.2.9, you will see that the struts DataSource utility is listed as "deprecated". In version 1.3.5 and above, it's been removed entirely. So, one reason not to use it is that it limits your ability to upgrade to a later version.

The main reason it's not recommended, though, is that it violates the MVC pattern. Database access belongs in model classes, but the Struts Datasource utility requires you to get the DataSource in an Action class, which is a controller class, not a model class.

The recommended means of accessing a Datasource in any Java EE web application is to use the application server's utilities to create a JNDI DataSource and then use a JNDI lookup in your code to retrieve it. The Tomcat documentation has information on how to do this. It's also discussed in this thread.

Regarding your "Class not found" problem, I believe your assessment is correct: Both the DBCP jar file and the MYSQL driver jar file must be loaded by the same classloader. So, you must either have both jars in the application class path, or in the server class path, but you can't have one in one path and one in the other.

Consultant, Sima Solutions
Sai Narasimha Reddy

Joined: Dec 13, 2006
Posts: 23
Thank you for your quick reply!
I agree. Here's the link:
subject: where to put my "mysql-5.0.3-bin.jar" file
Similar Threads
JDBC ....hmmmm
Can't find JDBC driver for project in MyEclipse
DataSource Not Found Struts with WSAD 5 & MySQL
Error while starting jboss(java.lang.ClassNotFoundException: No ClassLoaders found for: com.mysql.j)
JBOSS and Mysql