Starting with Spring DAO layer – Stored procedures/functions

Configuring Spring JDBC DAO-

Create a Java/or Dynamic Web project in eclipse.
Copy all the spring jar files from /dist/modules into your project’s lib folder and add these jar files to java build path.
Copy all the jar files (except commons-attributes-compiler.jar) from /lib/jakarta-commons into your project’s lib folder and add these jar files to java build path. (Without these libraries tomcat will complain the following Exception-
java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory)

Now you are all set to begin web development with Spring DAO layer.

Following I show how we can configure Datasource/and the beans that use datasource using applicationContext.xml. and also I will show you how we can call Database functions/stored procedures running on MS SQL Server.

Following is the applicationContext.xml, where you configure your beans, specify the database connection settings here in datasource bean definition.

Following is a simple java class that shows how to call a function and map input/output parameters -

Following is a simple java class that shows how to call a stored procedure and map input/output paremeters using a private inner class.

Following is a model object used by the above java class -

thats it..you have an application with DAO layer. You can use similiar approach in web applications, For standalone make sure you have applicationContext.xml in classpath. For web applications, have applicationContext.xml in WEB-INF folder and define a context parameter with name (contextConfigLocation) and value (/WEB-INF/applicationContext.xml)

Advertisement
Explore posts in the same categories: Spring Development

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.