File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Acessing a MySQL stored function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Acessing a MySQL stored function" Watch "Acessing a MySQL stored function" New topic

Acessing a MySQL stored function

Mike Tabak
Ranch Hand

Joined: Mar 31, 2012
Posts: 67
I'm going over an example from the Ho Prospring3 book. It writes an app to access a function stored in the MySQL database. The app uses annotation configuration. There are only 3 lines in the xml file:

<import resource="datasource-dbcp.xml/>

<context:component-scan base-package="com.apress.prospring3.ch8.dao.jdbc.annotation"/>


The book indicates the first line will import datasource.xml which contains the configuration to the MySQL database (which I have loaded and running with the example database). The goes on to indicate that to run this app. you need the Apache commons-dbcp.jar version 1.4. I put this dependency in my pom file and I can see commons-dbcp.1.4.jar loaded into my maven library folder. However, when I try to run the program I get the following error:

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [dataSource-dbcp.xml]
Offending resource: class path resource [app-context-sf.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:/D:/spring/workspace/Chp8SpringJDBCSupport/target/classes/dataSource-dbcp.xml]; nested exception is D:\spring\workspace\Chp8SpringJDBCSupport\target\classes\dataSource-dbcp.xml (The system cannot find the file specified)

Note that D:\spring is where my workspace is located. I'm not sure what exactly is wrong here, can someone help? It's seems to be looking for dataSource-dbcp.xml, but the book makes no mention of such a file. I was under the impression having commons-dbcp.1.4.jar in my build path would take care of it.

Thanks in advance
Mike Tabak
Ranch Hand

Joined: Mar 31, 2012
Posts: 67
Please disregard the previous post, I solved the problem. Thanks.
Wendy Gibbons

Joined: Oct 21, 2008
Posts: 1107

Could you let us know how, so that you can save anyone coming across your post the same heartache you had...
Mike Tabak
Ranch Hand

Joined: Mar 31, 2012
Posts: 67
Sure, I'll share, even though it was a P.O.K. error (person operating keyboard) and a little embarrassing......

The line <import resource="datasource-dbcp.xml"> imports the datasource-dbcp.xml file which contains the definitions to access the database. This file is in the same directory as the xml file containing the above statement and looks like:

<?xml version="1.0" encoding="UTF-8"?>
<beans xsi:schemaLocation=""

<!-- the jdbx.xxxx are read in from the file -->
<bean destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource" id="dataSource">
<property name="driverClassName">
<property name="url">
<property name="username">
<property name="password">
</property> </bean>

<!-- the following tag defines where the jdbc properties file is -->
<context:property-placeholder location=""/>


As you can see by the last tag <context:property-placeholder....> defines the property file where all of the ${jdbc.xxxxx} values com from. This file is also in the same directory and contains:


The last two lines define the login for the database. This file assumes the login name and password are both prospring3, which is not the case for my installation. I forgot to change the credentials. So my code was operating correctly, but I was not accessing the databbase. The example also had logging turned on so there was a ton of log statements coming out and I missed the one indicating I was not accessing the database.

I'm now on to a new example which uses java configuration to eliminate the XML file configuration. I initially got it working, but then I broke it somehow. But I'm not going to post anything until I exhaust debugging this time. Sorry to waste your time and I hope that this error does actually help someone, at least be sure you modify files correctly before you cut and paste them. I appreciate the help I have gotten on this site, I wish I could have offered some more significant solution other than a P.O.K.!

I did notice one thing about Spring. I usually backup my workspace each time I do an example. At one point I loaded the backup from when my example was working, but all my files were empty. I had to do a refresh to get them back. This seems a bit odd since the backup was just a copy of my workspace from a couple of hours previous and on the same machine. But I guess Spring keeps track of things. Once I refreshed, everything worked fine, except for the example I broke. I guess whatever I broke I saved also. So back to debugging that one.

Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

Thank you Mike!

OCUP UML fundamental and ITIL foundation
I agree. Here's the link:
subject: Acessing a MySQL stored function
It's not a secret anymore!