Skip to Content
avatar image
Former Member

How to get DB Connection using IConnectorService

Hi All

I need some documents or help on how to make a jdbc connection using IConnectorService framework. Can anybody help?

Warm Regards

Shubhadip

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Jul 31, 2004 at 12:30 AM

    Hi Shubhadip,

    I have some usefull code for you.

    //This method is to perform the connection to the DataBase, where

    // the Database name is myDatabase

    public IConnection getConnect()

    {

    IConnection myconnection = null;

    IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();

    Object connectorservic = PortalRuntime.getRuntimeResources().getService(IConnectorService.KEY);

    IConnectorGatewayService cgService = (IConnectorGatewayService)connectorservic;

    mylogger = request.getLogger();

    ConnectionProperties cp = new ConnectionProperties(request.getLocale(), request.getUser());

    try {

    myconnection = cgService.getConnection("myDatabase", cp);

    }

    catch (Exception e)

    {

    mylogger.severe(e.getMessage());

    }

    return myconnection;

    }

    Kind Regards,

    Al-Suwaiyel

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 31, 2004 at 12:34 AM

    Hi Shubhadip,

    However, I have forgot to inform you that the connection must be closed when there is no need for it, e.g. as in the former code the closing will be:

    try {

    myconnection.close();

    }

    catch (ResourceException e2) {

    e2.printStackTrace();

    }

    Add comment
    10|10000 characters needed characters exceeded