Show TOC

Accessing Data SourcesLocate this document in the navigation structure

Use

This section provides guidelines for managing database connections and for accessing information in a database from a portal application.

Managing Database Connections

Portal applications that need to access databases directly should not create connections themselves. Portal applications must use the built-in connection pools, to limit the number of concurrent connections and to prevent reducing resources, which may affect other applications.

The following example demonstrates how to get a connection from the JEE (engine) connection pool:

               try {
   ctx = new InitialContext();
   dataSource = (DataSource) ctx.lookup("<Data Source Alias Name>");
   Connection conn = dataSource.getConnection();
   }
catch (NamingException ne) {
. ..

            

Accessing Information in a Database

The following table provides guidelines for accessing, from a portal application, information in a database:

Method

Recommended

Description

Prepared statements

Yes

Prepared statements enable you to execute an SQL statement with parameters, where question marks represent each parameter. The SQL statement must be precompiled by the DBMS, and the current parameter values are assigned for every execution. In addition, prepared statements enable using values that cannot be expressed in SQL.

Prepared statements are strongly recommended for security reasons, and also for improving performance. Do not use regular statements.

Stored procedures

No

Stored procedures are written entirely in SQL and are executed on the database system. Stored procedures are not recommended by SAP, because they place the load on the database, which is the central resource, and thus restrict the scalability of the entire cluster or system. However, this constraint does not apply if your application only accesses a local database.