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
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/NewWebsite] threw exception [Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [call insert_contact_message(?, ?)]; ResultSet is from UPDATE. No Data.; nested exception is java.sql.SQLException: ResultSet is from UPDATE. No Data.] with root cause
java.sql.SQLException: ResultSet is from UPDATE. No Data.
I am wondering if the SQL routine needs to return some confirmation? Or maybe I am accessing the DB with the wrong information, is there a way of determining whether it even connected?
EDIT:
insert_contact_message looks like this:
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_contact_message`(
_author VARCHAR(45),
_message MEDIUMTEXT
)
BEGIN
INSERT INTO contact_messages (`author`, `message`, `date_sent`) VALUES (_author, _message, NOW());
END
You’re using
queryForInt, butinsert_contact_messagedoesn’t return a result. I haven’t usedJdbcTemplatebefore, but it looks like you might want to useexecutethat doesn’t expect a result set.Another option is to change from using a procedure to a function.