• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

How to assign HSQL Datasource to JdbcTemplate in DatabaseFacadeImpl?

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am currently working on a Spring Boot app, and am trying to assign a HSQL DB as the datasource of a JdbcTemplate in a DatabaseFacadeImpl class.

Below is what's currently in DatabaseFacade.java



And here is what is in DatabaseFacadeImpl.java:



Can someone please tell me what needs to be done so I can hook this up?

Most of the examples I've found online are using XML files for the configuration, but I don't know how to or want to use that approach.

I did some research on jdbcTemplate, & below is my attempt:



Should this work, or am I on the wrong track?
 
Bartender
Posts: 2266
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think you need to have a @Configuration class. Inside that class , you can define @Bean method that return a JdbcTemplate


The reason why I am defining JdbcTemplate as a bean because you use @Autowired to autowire JdbcTemplate in the DatabaseFacadeImpl class.
If jdbcTemplate is not a bean, you cannot autowire it.

Here is an example https://www.technicalkeeda.com/spring-tutorials/spring-4-jdbctemplate-annotation-example

reply
    Bookmark Topic Watch Topic
  • New Topic