I have been trying to access MySQL routines from my Spring project using SimpleJdbcDaoSupport.
I have a class called ‘AdminSimpleMessageManager’, which implements the interface ‘AdminMessageManager’.
‘AdminSimpleMessageManager’ has an instance of the class ‘AdminSimpleJdbcMessageDao’, which implements the interface ‘AdminMessageDao’.
AdminSimpleJdbcMessageDao has the following method:
public class AdminSimpleJdbcMessageDao extends SimpleJdbcDaoSupport implements AdminMessageDao {
public int addMessage(String from, String message) {
return getJdbcTemplate().queryForInt("call insert_contact_message(?, ?)", from, message);
}
}
I have included the following in my application context:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/OctagonDB"/>
</bean>
<bean id="adminMessageManager" class="Managers.AdminSimpleMessageManager">
<property name="adminMessageDao" ref="adminMessageDao"/>
</bean>
<bean id="adminMessageDao" class="Managers.dao.AdminSimpleJdbcMessageDao">
<property name="dataSource" ref="dataSource"/>
</bean>
but I feel there are a few important lines missing. I get the error
FAIL – Deployed application at context path /NewWebsite but context failed to start
among other things.
You need to include a MySQL JDBC driver in your classpath. Furthermore you should update the config of the driver class name to
com.mysql.jdbc.Driver.org.gjt.mm.mysql.Driveris only retained for backwards compatibility.However, since you seem to be loading the datasource through JNDI I guess the driver JAR should be in your container (which provides the datasource through JNDI) rather than in your app’s
WEB-INF/lib?