Using the JDBC Connector
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 :
|
IConnectionconnection= null ; //gettheConnectorGatewayService 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 (Exceptione){} 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:
|
//physicalconnection IConnection connection = null ; //connectionfactoryoftheJDBCconnectortogettheconnection IConnectionFactoryconnectionFactory;Contextinitctx= null ; try { //gettheinitialJNDIcontext Hashtableenv = new Hashtable() ; env.put( "domain" , "true" ); initctx= new com.sapportals.portal.prt.jndisupport.InitialContext(env); //performJNDIlookuptogettheconnectionfactory connectionFactory=(IConnectionFactory) initctx.lookup( "deployedAdapters/JDBCFactory/shareable/JDBCFactory" ); //retrievetheConnectionSpecandsetthevalues IConnectionSpecspec=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" ); //Retrievetheconnectionhandler connection =connectionFactory.getConnectionEx(spec);} catch (Exceptione){} finally { try { if (connection != null) { connection.close(); } } catch (ResourceException re) { } } |
See also