0

I've installed tomcat7 and mysql55 on my ami linux micro instance. I'm trying to figure out how to configure tomcat7 to communicate with mysql, but have had no luck. I've always been a glassfish user, so it was pretty simple to do through the gui, however with tomcat, I'm not sure how to configure this.

I've looked at the apache documentation on tomcat7, but found myself even more confused. I do not know where the files are I need to edit and I do not know what to edit them with. Do I need to install a mysql driver? Do I use JDBC or JNDI? My app is a Tapestry5 app that uses Hibernate, so I'm not sure if that matters.

Does anybody know of a nice guide or could provide me with example code on how to do this? Just for the record, I only have a couple hours behind the wheel of linux, so I'm very green when it comes to anything linux related.

UPDATE

I found the following default configuration

<!--    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
-->

I'm using hibernate and in the hibernate.cfg.xml I'm using the following

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.datasource">jdbc/mydatabase</property>

I commented out the above resource and added the following, but this also doesn't seem to work. I also noticed I no longer have access to the tomcat manager either.

<Resource type="javax.sql.DataSource"
            name="jdbc/mydatabase"
            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
            driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/mysql"
            username="root"
            password="password"
/>

I added the following to the context.xml file

<ResourceLink type="javax.sql.DataSource"
                name="jdbc/mydatabase"
                global="jdbc/mydatabase"

Does anybody know what I'm doing wrong with this configuration?

1 Answer 1

1

You need to install a JDBC driver, here is the link:

http://dev.mysql.com/downloads/connector/j/3.1.html

You then need to add to the classpath, there are many ways to do it, to test just try to put the jar file in the lib directory under your Tomcat 7 installation.

The "tomcat-users.xml" has nothing to do with database connectivity, it's related to authentication realms, and this is why you can't see manager webapp now.

You are on the right track setting up the resource.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.