• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

How to assign HSQL Datasource to JdbcTemplate in DatabaseFacadeImpl?

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • 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?
 
Ranch Hand
Posts: 1772
12
  • Mark post as helpful
  • send pies
  • 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

 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!