That code is very incomplete.  It's hard to see what you're trying to do.

Why are you accessing the DataSource directly?  How are you even doing that?

In any case, why don't you just use the JdbcDaoTemplate and call getConnection().  Then you never have to worry about opening and closing connections (something you shouldn't be doing inside of a DAO anyway).

Clinton


On 5/24/05, Folashade Adeyosoye <[EMAIL PROTECTED]> wrote:

Can some please post a sample code using the javax.sql.DataSource; to get connection and to also close the connection in the try final….

 

Something like this…

 

Thanks

 

 

import javax.sql.DataSource;

 

DataSource dataSource ;

 

    try {

      connection = dataSource.getConnection();

      statement = connection.prepareStatement(sql.toString());

 

      statement.setString(1, APPROVED);

      statement.setString(2, objectType);

 

      resultSet = statement.executeQuery();

 

      objectList = copyResultSetToVO(resultSet);

    }

    catch (SQLException sqlEx) {

      throw new DaoException(sqlEx.getMessage());

    }

    catch (Exception ex) {

      throw new DaoException(ex.getMessage());

    }

    finally {

      //DBUtils.closeResultSet(resultSet);

     // DBUtils.closeStatement(statement);

      //DBUtils.closeConnection(connection);

 

            HOW DO I MAKE SURE THE CONNECTION IS PLACED BACK IN THE DAO POOL TO BE REUSED

    }

 

 

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

 

<!DOCTYPE daoConfig

    PUBLIC "-//iBATIS.com//DTD DAO Configuration 2.0//EN"

    "http://www.ibatis.com/dtd/dao-2.dtd">

 

<daoConfig>

 

<properties resource="net/naijatek/fgconline/properties/database_local.properties"/>

 

  <context>

 

   <transactionManager type="JDBC">

      <property name="DataSource" value="SIMPLE"/>

      <property name="JDBC.Driver" value="${driver}"/>

      <property name="JDBC.ConnectionURL" value="${url}"/>

      <property name="JDBC.Username" value="${username}"/>

      <property name="JDBC.Password" value="${password}"/>

      <property name="JDBC.DefaultAutoCommit" value="true"/>

      <property name="Pool.MaximumActiveConnections" value="10"/>

      <property name="Pool.MaximumIdleConnections" value="5"/>

      <property name="Pool.MaximumCheckoutTime" value="120000"/>

    </transactionManager>

 

    <dao interface="net.naijatek.fgconline.persistence.iface.MemberDAO" implementation="net.naijatek.fgconline.persistence.jdbcsql.MysqlMemberDAO"/>

  </context>

</daoConfig>

 


Reply via email to