ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Folashade Adeyosoye" <sharda...@gmail.com>
Subject Sample Code using javax.sql.DataSource
Date Tue, 24 May 2005 17:36:35 GMT
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>

 


Mime
View raw message