{"id":18018,"date":"2013-10-14T19:00:10","date_gmt":"2013-10-14T16:00:10","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=18018"},"modified":"2013-10-14T09:06:27","modified_gmt":"2013-10-14T06:06:27","slug":"getting-started-with-spring-jdbc-in-a-web-application","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html","title":{"rendered":"Getting started with Spring JDBC in a web application"},"content":{"rendered":"<p>I have shown you how to setup a <a href=\"http:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-annotation-based-spring-mvc-web-application.html\">basic Spring 3 MVC web application<\/a> in my previous article. Reusing that project setup as template, I will show you how to enhance it to work with JDBC. With this you can store and retrieve data from database. We will add a new controller and a data service through Spring so you can see how Spring injection and annotation configuration works together.<\/p>\n<p>A direct JDBC based application is easy to setup in comparison to a full ORM such as Hibernate. You don\u2019t need to worry AOP, TranactionManager, Entity mapping and full array of other configurations. On top of the JDK\u2019s <code>java.jdbc<\/code> API, the Spring comes with <code>spring-jdbc<\/code> module that can boots your productively with their well known <code>JdbcTemplate<\/code> class. Let\u2019s explore how this can be setup and run as web application.<\/p>\n<h2>Getting started and project setup<\/h2>\n<p>For demo purpose, I will use the in-memory version of H2Database as JDBC store. It\u2019s simple to use and setup. And if you decided to use their FILE or TCP based database, you would simply have to re-set the datasource, and you may continue to explore more.<\/p>\n<p>We will start by adding new dependencies to your existing <code>spring-web-annotation\/pom.xml<\/code> file.<\/p>\n<pre class=\" brush:java\">&lt;dependency&gt;\r\n   &lt;groupId&gt;com.h2database&lt;\/groupId&gt;\r\n   &lt;artifactId&gt;h2&lt;\/artifactId&gt;\r\n   &lt;version&gt;1.3.163&lt;\/version&gt;\r\n  &lt;\/dependency&gt;\r\n  &lt;dependency&gt;\r\n   &lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n   &lt;artifactId&gt;spring-jdbc&lt;\/artifactId&gt;\r\n   &lt;version&gt;3.2.4.RELEASE&lt;\/version&gt;\r\n  &lt;\/dependency&gt;<\/pre>\n<p>With this, you will have access to Spring module classes for configuration. Find the previous <code>src\/main\/java\/springweb\/WebApp.java<\/code> file in your existing project and add what\u2019s new compare to below:<\/p>\n<pre class=\" brush:java\">package springweb;\r\n\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.context.annotation.ComponentScan;\r\nimport org.springframework.context.annotation.Configuration;\r\nimport org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;\r\nimport org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;\r\nimport org.springframework.web.servlet.config.annotation.EnableWebMvc;\r\nimport org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;\r\n\r\nimport javax.sql.DataSource;\r\n\r\npublic class WebApp extends AbstractAnnotationConfigDispatcherServletInitializer {\r\n    @Override\r\n    protected Class&lt;?&gt;[] getRootConfigClasses() {\r\n        return new Class&lt;?&gt;[]{ RootConfig.class };\r\n    }\r\n\r\n    @Override\r\n    protected Class&lt;?&gt;[] getServletConfigClasses() {\r\n        return new Class&lt;?&gt;[]{ WebAppConfig.class };\r\n    }\r\n\r\n    @Override\r\n    protected String[] getServletMappings() {\r\n        return new String[]{ \"\/\" };\r\n    }\r\n\r\n @Configuration\r\n    @EnableWebMvc\r\n    @ComponentScan(\"springweb.controller\")\r\n    public static class WebAppConfig {\r\n    }\r\n\r\n @Configuration\r\n @ComponentScan(\"springweb.data\")\r\n public static class RootConfig {\r\n  @Bean\r\n  public DataSource dataSource() {\r\n   DataSource bean = new EmbeddedDatabaseBuilder()\r\n     .setType(EmbeddedDatabaseType.H2)\r\n     .addScript(\"classpath:schema.sql\")\r\n     .build();\r\n   return bean;\r\n  }\r\n }\r\n}<\/pre>\n<p>What\u2019s new in here is we introduced a new <code>RootConfig<\/code> class that will be loaded inside <code>getRootConfigClasses()<\/code> method. The <code>RootConfig<\/code> is just another Spring annotation based configuration that creates a new Spring context for bean definitions. We\u2019ve created a bean there that will run the in-memory database. The bean returned by the builder also conveniently implemented the <code>javax.sql.DataSource<\/code> interface, so we can actually inject this into any data service and start using it immediately.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>One more cool thing about the Spring embedded database builder is that it also runs any SQL script as part of the startup! For this demo, we will create a <code>PING<\/code> table in the <code>src\/main\/resources\/schema.sql<\/code> file. This file is visible to Spring as in root of the CLASSPATH due to Maven standard source structure.<\/p>\n<pre class=\" brush:java\">CREATE TABLE PING (\r\n  ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,\r\n  TAG VARCHAR(1024) NOT NULL,\r\n  TS DATETIME NOT NULL\r\n);<\/pre>\n<p>That\u2019s the datasource setup. Now notice that I did not add this datasource Spring bean definition into existing <code>WebAppConfig<\/code> class. The reason is that we want a separate Spring context to configure all service level beans, while reserving the <code>WebAppConfig<\/code> for all Spring MVC related beans (such as Controller, URL mapping etc). This helps organize your bean definitions in hierarchical order of Spring contexts; with <code>RootConfig<\/code> as parent and <code>WebAppConfig<\/code> as child layers. This also means that all service beans in <code>RootConfig<\/code> are automatically visible to <code>WebAppConfig<\/code>; for the purpose of injection etc.<\/p>\n<p>Also notice that with separated config classes, we are able to specify two distinct packages to scan for service components; we use <code>springweb.controller<\/code> for <code>WebAppConfig<\/code> and <code>springweb.data<\/code> for <code>RootConfig<\/code>. This is important and it can save you some troubles letting Spring auto detecting your all these annotation based components.<\/p>\n<h2>Creating Data Service<\/h2>\n<p>Now it\u2019s time we use the JDBC, so let\u2019s write a data service class under <code>src\/main\/java\/springweb\/data\/PingService.java<\/code> file.<\/p>\n<pre class=\" brush:java\">package springweb.data;\r\n\r\nimport org.apache.commons.logging.Log;\r\nimport org.apache.commons.logging.LogFactory;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.jdbc.core.JdbcTemplate;\r\nimport org.springframework.stereotype.Repository;\r\n\r\nimport javax.sql.DataSource;\r\nimport java.util.Date;\r\nimport java.util.List;\r\nimport java.util.Map;\r\n\r\n@Repository\r\npublic class PingService {\r\n    public static Log LOG = LogFactory.getLog(PingService.class);\r\n\r\n    private JdbcTemplate jdbcTemplate;\r\n\r\n    @Autowired\r\n    public void setDataSource(DataSource dataSource) {\r\n        this.jdbcTemplate = new JdbcTemplate(dataSource);\r\n    }\r\n\r\n    public void insert(String tag) {\r\n        LOG.info(\"Inserting Ping tag: \" + tag);\r\n        jdbcTemplate.update(\"INSERT INTO PING(TAG, TS) VALUES(?, ?)\", tag, new Date());\r\n    }\r\n\r\n    public List&lt;Map&lt;String, Object&gt;&gt; findAllPings() {\r\n        return jdbcTemplate.queryForList(\"SELECT * FROM PING ORDER BY TS\");\r\n    }\r\n}<\/pre>\n<p>The service is very straight forward. I expose two methods: one for insert and one for retrieve all Ping data. Noticed that I used <code>@Repository<\/code> to indicate to Spring that this class is a component service that perform data service. Also note how we inject the <code>DataSource<\/code> using a setter method, and then instantiate the <code>JdbcTemplate<\/code> as member field. From that we can take full advantage of the Spring JDBC API for query and update.<\/p>\n<p>A note on logging. Spring core itself uses Apache <code>common-logging<\/code>, so I reused that API without even explicitly declare them in my <code>pom.xml<\/code>. If you want to see more details from log output, you should add <code>log4j<\/code> logger implementation to the project, and it should automatically work. I will leave that as your exercise.<\/p>\n<p>Next we will need to write a Controller that can bring data to web UI page. We will create this under <code>src\/main\/java\/springweb\/controller\/PingController.java<\/code> file.<\/p>\n<pre class=\" brush:java\">package springweb.controller;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.PathVariable;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.ResponseBody;\r\nimport springweb.data.PingService;\r\n\r\nimport java.util.List;\r\nimport java.util.Map;\r\n\r\n@Controller\r\npublic class PingController {\r\n\r\n    @Autowired\r\n    private PingService pingService;\r\n\r\n    @RequestMapping(value=\"\/ping\/{tag}\", produces=\"text\/plain\")\r\n    @ResponseBody\r\n    public String pingTag(@PathVariable(\"tag\") String tag) {\r\n        pingService.insert(tag);\r\n        return \"Ping tag '\" + tag + \"' has been inserted. \";\r\n    }\r\n\r\n    @RequestMapping(value=\"\/pings\", produces=\"text\/plain\")\r\n    @ResponseBody\r\n    public String pings() {\r\n        List&lt;Map&lt;String, Object&gt;&gt; result = pingService.findAllPings();\r\n  if (result.size() == 0)\r\n   return \"No record found.\";\r\n\r\n        StringBuilder sb = new StringBuilder();\r\n        for (Map&lt;String, Object&gt; row : result) {\r\n            sb.append(\"Ping\" + row).append(\"\\n\");\r\n        }\r\n        return sb.toString();\r\n    }\r\n}<\/pre>\n<p>In this controller, you can easily see that the Ping data is fetched and updated through our data service by injection. I\u2019ve declared and map URL <code>\/ping\/{tag}<\/code> to insert Ping data into the database. Spring has this very nice short hand syntax annotation mapping that can extract parameter from your URL. I allow user to set a simple tag word to be insert as Ping record so we can identify the source in database.<\/p>\n<p>The other controller handler <code>\/pings<\/code> URL is very straight forward; it simply returns all the records from PING table.<\/p>\n<p>For demo purpose, I choose to not use JSP as view, but to return plain text directly from the Controller. Spring let you do this by adding <code>@ResponseBody<\/code> to the handler method. Notice also we can specify the content type as <code>text\/plain<\/code> as output directly using the annotation.<\/p>\n<h2>Testing<\/h2>\n<p>To see your hard labor with above, you simply need to run the Maven tomcat plugin. The previous article has shown you an command to do that. Once you restarted it, you should able to open a browser and use these URLS for testing.<\/p>\n<ul>\n<li><a href=\"http:\/\/localhost:8081\/spring-web-annotation\/ping\/tester1\">http:\/\/localhost:8081\/spring-web-annotation\/ping\/tester1<\/a><\/li>\n<li><a href=\"http:\/\/localhost:8081\/spring-web-annotation\/ping\/tester2\">http:\/\/localhost:8081\/spring-web-annotation\/ping\/tester2<\/a><\/li>\n<li><a href=\"http:\/\/localhost:8081\/spring-web-annotation\/ping\/tester3\">http:\/\/localhost:8081\/spring-web-annotation\/ping\/tester3<\/a><\/li>\n<li><a href=\"http:\/\/localhost:8081\/spring-web-annotation\/pings\">http:\/\/localhost:8081\/spring-web-annotation\/pings<\/a><\/li>\n<\/ul>\n<h2>Happing programming<\/h2>\n<p>From this simple exercise, you can quickly see Spring MVC brings you many benefits; and a lot of fun in developing web application. Spring, by design principles, tends to be developers friendly, boots productivity and un-intrusively in your environment. It\u2019s one of the reason I like to work with it a lot. I hope you enjoy this tutorial and go further explore on your own.<\/p>\n<p>Happy programming!<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/saltnlight5.blogspot.com\/2013\/10\/getting-started-with-spring-jdbc-in-web.html\">Getting started with Spring JDBC in a web application<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Zemian Deng at the <a href=\"http:\/\/saltnlight5.blogspot.com\/\">A Programmer&#8217;s Journal<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I have shown you how to setup a basic Spring 3 MVC web application in my previous article. Reusing that project setup as template, I will show you how to enhance it to work with JDBC. With this you can store and retrieve data from database. We will add a new controller and a data &hellip;<\/p>\n","protected":false},"author":267,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30],"class_list":["post-18018","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Getting started with Spring JDBC in a web application<\/title>\n<meta name=\"description\" content=\"I have shown you how to setup a basic Spring 3 MVC web application in my previous article. Reusing that project setup as template, I will show you how to\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting started with Spring JDBC in a web application\" \/>\n<meta property=\"og:description\" content=\"I have shown you how to setup a basic Spring 3 MVC web application in my previous article. Reusing that project setup as template, I will show you how to\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-10-14T16:00:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Zemian Deng\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Zemian Deng\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html\"},\"author\":{\"name\":\"Zemian Deng\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/decbcaa8856a153c212bedba0079233a\"},\"headline\":\"Getting started with Spring JDBC in a web application\",\"datePublished\":\"2013-10-14T16:00:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html\"},\"wordCount\":959,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html\",\"name\":\"Getting started with Spring JDBC in a web application\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2013-10-14T16:00:10+00:00\",\"description\":\"I have shown you how to setup a basic Spring 3 MVC web application in my previous article. Reusing that project setup as template, I will show you how to\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/10\\\/getting-started-with-spring-jdbc-in-a-web-application.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Getting started with Spring JDBC in a web application\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/decbcaa8856a153c212bedba0079233a\",\"name\":\"Zemian Deng\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a52e12ea83eca65c46f00caeddaf307d5d531c3d28ad5219d7bd7e27c45e373f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a52e12ea83eca65c46f00caeddaf307d5d531c3d28ad5219d7bd7e27c45e373f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a52e12ea83eca65c46f00caeddaf307d5d531c3d28ad5219d7bd7e27c45e373f?s=96&d=mm&r=g\",\"caption\":\"Zemian Deng\"},\"sameAs\":[\"http:\\\/\\\/saltnlight5.blogspot.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Zemian-Deng\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Getting started with Spring JDBC in a web application","description":"I have shown you how to setup a basic Spring 3 MVC web application in my previous article. Reusing that project setup as template, I will show you how to","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html","og_locale":"en_US","og_type":"article","og_title":"Getting started with Spring JDBC in a web application","og_description":"I have shown you how to setup a basic Spring 3 MVC web application in my previous article. Reusing that project setup as template, I will show you how to","og_url":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-10-14T16:00:10+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Zemian Deng","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Zemian Deng","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html"},"author":{"name":"Zemian Deng","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/decbcaa8856a153c212bedba0079233a"},"headline":"Getting started with Spring JDBC in a web application","datePublished":"2013-10-14T16:00:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html"},"wordCount":959,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html","url":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html","name":"Getting started with Spring JDBC in a web application","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2013-10-14T16:00:10+00:00","description":"I have shown you how to setup a basic Spring 3 MVC web application in my previous article. Reusing that project setup as template, I will show you how to","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2013\/10\/getting-started-with-spring-jdbc-in-a-web-application.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Getting started with Spring JDBC in a web application"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/decbcaa8856a153c212bedba0079233a","name":"Zemian Deng","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a52e12ea83eca65c46f00caeddaf307d5d531c3d28ad5219d7bd7e27c45e373f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a52e12ea83eca65c46f00caeddaf307d5d531c3d28ad5219d7bd7e27c45e373f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a52e12ea83eca65c46f00caeddaf307d5d531c3d28ad5219d7bd7e27c45e373f?s=96&d=mm&r=g","caption":"Zemian Deng"},"sameAs":["http:\/\/saltnlight5.blogspot.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Zemian-Deng"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/18018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/267"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=18018"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/18018\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=18018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=18018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=18018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}