I setup a sample application in Tomcat but have trouble getting the database connection working. It is a standard WAR package written in Spring framework and uses a MySQL database.
The application is the Granny Address Book from http://www.cumulogic.com/downloads/sample-applications/.
I have deployed it under tomcat/webapps/
(Tomcat 7.0.42 with MySQL 5.1.73 running on the same host.)
- Mysql DB name:
grannydb
- JNDI Name:
MySqlGBDS
I cannot locate where to place the database connection settings, as it does not have the usual database.properties
file. The only reference to database settings are in granny.xml
:
MySQL-5.5.27
1
10
demo
demodemo
3306
UTF-8
But this file is not packaged inside the webapp (it comes separately,) and it's lacking a database host name.
I tried placing granny.xml
inside the webapp, under WEB-INF/classes/META-INF/spring/
but it fails to connect to the database.
The current behavior is the webapp is starting but catalina.out
warns:
WARN : org.hibernate.cfg.SettingsFactory - Could not obtain connection
to query metadata org.apache.tomcat.dbcp.dbcp.SQLNestedException:
Cannot create JDBC driver of class '' for connect URL 'null'
Where should granny.xml
be placed?
What else is missing?
(Yes I did already create the database and user in MySQL. No tables are getting created by the app.)
Answer
If it uses JNDI you need to set up the database connection in either server.xml
or context.xml
.
As an administrator it is better to setup the database connection in server.xml
, otherwise you end up unpacking and packing the WAR-file before each deployment.
Open server.xml. There should be a section called GlobalNamingResources
. Here you add your database connection.
driverClassName="com.mysql.jdbc.Driver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
validationQuery="/* ping */"
testOnBorrow="true"
name="jdbc/MySqlGBDS"
username=""
password=""
type="javax.sql.DataSource"
url="jdbc:mysql:///grannydb" />
Hope this helps.
Comments
Post a Comment