Show TOC Start of Content Area

Background documentation Using the JDBC Connector  Locate the document in its SAP Library structure

The JDBC adapter for the SAP Enterprise Portal 6.0 is a connector framework implementation based on JDBC.

There are two basic ways to get a connection using the JDBC Connector:

●     Via the Connector Service—this approach being faster, simpler, and benefits from the portal’s user mapping from the system

●     Direct connection using the J2EE JNDI

Connecting via the Connector Service

Example for a connection to a JDBC system using the connector service:

IConnection connection = null;
// get the Connector Gateway Service

String jdbcSystem = "pubs";
IConnectorGatewayService cgService = (IConnectorGatewayService)

         PortalRuntime.getRuntimeResources().getService(IConnectorService.KEY);

ConnectionProperties cp = new ConnectionProperties(portalRequest.getLocale(),

         portalRequest.getUser());    

try {
    connection = cgService.getConnection(jdbcsystem, cp);

} catch (Exception e) {
}
finally {

    try {

        if (connection != null) {

            connection.close();

        }

    } catch (ResourceException re) {

    }

}

 

Connecting via J2EE

Example for a connection to a JDBC system using the J2EE JNDI:

// physical connection
IConnection connection = null;
//connection factory of the JDBC connector to get the connection
IConnectionFactory connectionFactory;
Context initctx = 
null;
try {
    
//get the initial JNDI context
    
Hashtable env = new Hashtable();

    env.put("domain", "true");
    initctx = 
new com.sapportals.portal.prt.jndisupport.InitialContext(env);
    
// perform JNDI lookup to get the connection factory
    
connectionFactory = (IConnectionFactory)

           initctx.lookup("deployedAdapters/JDBCFactory/shareable/JDBCFactory");
    
// retrieve the ConnectionSpec and set the values
    
IConnectionSpec spec = connectionFactory.getConnectionSpec();
    // set properties
    
spec.setPropertyValue("UserName", "sa");
    spec.setPropertyValue(
"Password", "admin");
    spec.setPropertyValue(
"driver", "com.sap.portals.jdbc.sqlserver.SQLServerDriver");
    spec.setPropertyValue(
"url","jdbc:sap:sqlserver://localhost:1433;DatabaseName=Northwind");
    
// Retrieve the connection handler
    
connection = connectionFactory.getConnectionEx(spec);
} 
catch (Exception e) {
}
finally {

    try {

        if (connection != null) {

            connection.close();

        }

    } catch (ResourceException re) {

    }

}

 

See also

Prerequisites for using a connector

 

 

 

End of Content Area