ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Folashade Adeyosoye" <sharda...@gmail.com>
Subject RE: Sample Code using javax.sql.DataSource
Date Wed, 25 May 2005 15:01:34 GMT
Thank you very much; I actually extended "JdbcDaoTemplate" in my
"BaseJdbcDao" class that is in turn extended in my MysqlMemberDAO

 

 

 

public class BaseJdbcDao extends JdbcDaoTemplate {

 

 

public class MysqlMemberDAO extends BaseJdbcDao implements MemberDAO {

 

 

 And now I can just use   "getConnection()" in the MysqlMemberDAO class.

 

 

Thanks

 

 

 

 

  _____  

From: Clinton Begin [mailto:clinton.begin@gmail.com] 
Sent: Wednesday, May 25, 2005 12:34 AM
To: ibatis-user-java@incubator.apache.org
Subject: Re: Sample Code using javax.sql.DataSource

 


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 <shardayyy@gmail.com> 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
<http://www.ibatis.com/dtd/dao-2.dtd%22> ">

 

<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