Announcement Announcement Module
No announcement yet.
Closing of jdbc connection? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Closing of jdbc connection?

    Newbie question

    I have defined a bean like this:

    <bean id="theDWHDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
    <property name="url" value="" />
    <property name="username" value="BLABLA" />
    <property name="password" value="BLABLA" />

    I use spring to inject this bean into my dao class by the normal way (setDataSource), and from this datasource I open a connection, like:


    My question is this: will I need to close the connection or does spring handle this for me?

    Currently I am not using the jdbctemplate, but if I do will spring then handle the connections for me?

  • #2
    When posting code please use the [ code][/code ] tags...

    If you obtain a connection yourself you will also need to take care of that connection and all the exceptions that can occur. Switch to a JdbcTemplate and spring will manage it for you.