Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7623839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:48:26+00:00 2026-05-31T04:48:26+00:00

I have datasource bean initialized in the spring context. I wonder what way should

  • 0

I have datasource bean initialized in the spring context. I wonder what way should be used? Why I just can not write dataSource.getConnection()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:48:27+00:00Added an answer on May 31, 2026 at 4:48 am

    There is one important difference: dataSource.getConnection() always returns a new connection obtained from the dataSource or connection pool. DataSourceUtils.getConnection() checks if there is an active transaction for the current thread. If there is one, it will return connection with this transaction. If there is none it will behave exactly the same way as dataSource.getConnection().

    You need to be careful when using DataSourceUtils.getConnection(). If it returns connection for the active transaction it means someone else will be closing it since it’s the responsibility of whoever opened the transaction. On the other hand, if it returns a brand new connection from the dataSource it’s you who should commit/rollback/close it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Hibernate Transaction manager configured inside Spring MVC controller. <bean id=dataSource class=org.apache.commons.dbcp.BasicDataSource destroy-method=close>
I have the following partial spring context xml file: <bean name=template class=org.springframework.jdbc.core.JdbcTemplate> <property name=dataSource
We have an application where we have used spring for IOC. We have the
Hello all I have a simple Spring application which will not end as there
I have a simple app that use org.springframework.jdbc.datasource.DataSourceTransactionManager to manage the transactions. My spring
can someone please tell me what in my ApplicationContext I have to use beans:bean
I have a SpringMVC+Hibernate web application with the following files: applicationContext.xml <bean id=dataSource destroy-method=close
i have a small maven project with <artifactId>spring-core</artifactId> <artifactId>spring-test</artifactId> <artifactId>spring-beans</artifactId> <artifactId>spring-context</artifactId> <artifactId>spring-aop</artifactId> <artifactId>spring-context-support</artifactId> <artifactId>spring-tx</artifactId>
I learned that to configure c3p0 pooling in hibernate, we can have write the
I am trying to create a datasource bean for MySQL from within my Spring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.