Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
Applies to: SAP Netweaver Portal 7.0
SAP Composite Environment 7.1 SR5
SAP Composite Environment 7.1 EHP1
For more information, visit the Portal and Collaboration homepage.
Summary This document provides step by step guidance on how to create JDBC Datasource and system in Netweaver 7.0 and Composite Environment 7.1.
Author: Pankaj Prasoon
Company: Infosys Technologies Limited
Created on: 26 December 2008
Author Bio Pankaj has 2 years of experience in Netweaver. He has worked on JS, J2SE, J2EE, SAP-HTMLB, SAP-Portal Components, Enterprise Portal, MDM, Web Dynpro, Visual Composer, Knowledge Management, XML Form Builders, Composite Environment, ESR, Adobe Forms and ABAP. He has sound understanding of Netweaver Landscape and has been instrumental in designing them.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 1
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
Table of Contents Introduction .........................................................................................................................................................3
Purpose & Scope ............................................................................................................................................3 JDBC Datasource ...............................................................................................................................................3
Netweaver Portal 7.0.......................................................................................................................................3 Login to Visual Administrator (Create JDBC 2.0 Driver) ..............................................................................................3 Console Administration (Create JDBC 2.0 Driver) .......................................................................................................8 Log in to Visual Administrator (Create JDBC 1.x Driver)..............................................................................................8
Composite Environment 7.1/ Composite Environment 7.1 EHP1 ................................................................12 Systems on Netweaver Portal ..........................................................................................................................15
JDBC System on Netweaver 7.0 ..................................................................................................................15 BI JDBC System ...........................................................................................................................................17
Connecting to Visual Admin using P4 Port.......................................................................................................18 Driver and Connection URL..............................................................................................................................21 Sample code.....................................................................................................................................................21 Related Content................................................................................................................................................23 Disclaimer and Liability Notice..........................................................................................................................24
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 2
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
Introduction
Purpose & Scope
We can use Visual Administrator or Console administrator to create a standalone Datasource to connect to the database. It is deployed on the server as an application that contains only the deployment descriptor for the Datasource object. In this section we will see how to create a Datasource for an Oracle Database, the step remain same only the driver files, connection URL changes.
The document describes the configuration required to connect to the database using SAP Netweaver Visual Admin. The document does not cover the fine tuning of the Datasource as this entirely depends on the database and application parameters.
JDBC Datasource
Netweaver Portal 7.0
Following are the types of Datasource which can be created using the visual administrator.
• Creating a Datasource with JDBC 1.x Driver
• Creating a Datasource with JDBC 2.0 Driver
It is deployed on the server as an application that contains only the deployment descriptor for the Datasource object. Most of the JDBC 2.0-compliant drivers have specific properties. To enter them, use the Additional tab of JDBC Connector Service runtime control.
Login to Visual Administrator (Create JDBC 2.0 Driver)
Following are the steps to create a datasource using Visual Administrator.
1. Login to Visual administrator using the administrator ID.
2. Navigate to Server Services JDBC Connector
3. Choose Create New Driver or Datasource on the toolbar.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 3
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
We would be first uploading the necessary driver required for database connection to be made.
4. Enter the Driver Name. Click on Ok
5. Select the driver to connect to the database incase of Oracle it is classes.zip or classes.jar. Press Ok
once completed.
6. The driver details are uploaded as shown in the figure below
.
7. Click on Datasource.
8. Click on Press on Create New Driver or Datasource.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 4
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
9. Enter the details in the screen below
.
• Application Name: - The system uses this name for the configuration xml which holds all the data. We can leave it blank also it will get filled automatically.
Eg: - mydatasourceapp
• Name: - Specify a unique name for the Datasource. It is used when we look up the Datasource in the naming.
Eg: - mydatasourceapp
• Aliases: - We can create alias to access the same configuration from different applications.
Eg: - mydatasource1.
• Driver Name: - Choose the name of the driver we created in the earlier step.
Eg: - ORACLE_DRIVER
• JDBC Version: - Choose 2.0 with XA Support.
• Object Factory: - The object factory is used to reconstruct objects after their references are looked up from the JNDI namespace.
Eg: - oracle.jdbc.pool.OracleDataSourceFactory
• Datasource Type :- Choose one of the available options from the drop-down menu:
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 5
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
o ConnectionPoolDataSource – if you choose this option, you obtain a Connection pool datasource directly from the driver
o XADataSource – with this option you obtain a XADS from JDBC Connector Service
• CPDS Classname/XADS Classname: - The value of this field depends on the choice of datasource type.
o oracle.jdbc.pool.OracleConnection.PoolDataSource
o oracle.jdbc.xa.client.OracleXADataSource
10. Navigate to the additional Tab once you have finished entering all the data in the Main Tab. Enter
the following details
o Key and Value
User: - User id to connect to the database.
Password: - the Password for the user id to connect to the database.
URL: - It is the database connection string.
o Connection Pooling: Based on the requirements we can optimize the number of connection and Pool settings.
o SQL Engine: - Check the Vendor SQL for Oracle.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 6
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
11. Navigate to the DB Initialization and enter a dummy query, select execute.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 7
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
Console Administration (Create JDBC 2.0 Driver)
We need to make use of make_data_source command along with the datasource XML descriptor to create a Datasource.
Refer to the following link for more details
http://help.sap.com/saphelp_nw2004s/helpdata/en/64/0bee3da7138e5be10000000a114084/frameset.htm.
Log in to Visual Administrator (Create JDBC 1.x Driver)
Following are the steps to create a Datasource using Visual Administrator.
1. Login to Visual administrator using the administrator ID.
2. Navigate to Server Services JDBC Connector
3. Choose Create New Driver or Datasource on the toolbar.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 8
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
We would be first uploading the necessary driver required for database connection to be made.
4. Enter the Driver Name. Click on Ok
5. Select the driver to connect to the database incase of Oracle it is classes.zip or classes.jar. Press Ok
once completed.
6. The driver details are uploaded as shown in the figure below
.
7. Click on Datasource.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 9
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
8. Click on Press on Create New Driver or Datasource.
9. Enter the details in the screen below
.Application Name: - The system uses this name for the configuration xml which holds all the data. We can leave it blank also it will get filled automatically.
Eg: - mydatasourceapp
• Name: - Specify a unique name for the DataSource. It is used when we look up the DataSource in the naming.
Eg: - mydatasource
• Aliases: - We can create alias to access the same configuration from different applications.
Eg: - mydatasource1.
• Driver Name: - Choose the name of the driver we created in the earlier step.
Eg: - ORACLE_DRIVER
• JDBC Version: - Choose 1.x with No XA Support.
• Driver Class: - Enter the fully Java qualified name of the driver’s main class.
Eg: - oracle.jdbc.driver.OracleDriver
1. Database URL: - It specifies the Connection URL to connect to the database.
2. User: - User Id to connect to the database.
3. Password: - Password for the used id used for connecting to the database.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 10
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
Navigate to the DB Initialization and enter a dummy query, select execute.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 11
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
Composite Environment 7.1/ Composite Environment 7.1 EHP1
In this scenario we would be creating an Oracle Database Datasource.
1. Login to NWA (http://<HOSTNAME>:<PORT>/nwa)
2. Navigate to Configuration Management->Infrastructure->Application Resources
3. Uploading the JDBC Connections Driver
4. Enter the name for the driver and Click on add New Driver File.
5. Browse the JDBC driver file and click on OK.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 12
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
6. Click on save to create JDBC Driver.
7. Close the confirmation pop-up.
8. Click on New JDBC Custom Datasource
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 13
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
9. Enter the details about the JDBC Datasource
• Application Name: - The system uses this name for the configuration xml which holds all the
data. We can leave it blank also it will get filled automatically.
Eg:- mydatasourceapp
• Name: - Specify a unique name for the Datasource. It is used when we look up the Datasource in the naming.
Eg:- mydatasource
• Aliases: - We can create alias to access the same configuration from different applications.
Eg:- mydatasource1.
• Driver Name: - Choose the name of the driver we created in the earlier step.
Eg:- ORACLE_DRIVER
• JDBC Version: - Choose 2.0 with XA Support.
• Object Factory: - The object factory is used to reconstruct objects after their references are looked up from the JNDI namespace.
Eg: - oracle.jdbc.pool.OracleDataSourceFactory
• Datasource Type :- Choose one of the available options from the drop-down menu:
o ConnectionPoolDataSource – if you choose this option, you obtain a Connection pool datasource directly from the driver
o XADataSource – with this option you obtain a XADS from JDBC Connector Service
• CPDS Classname/XADS Classname: - The value of this field depends on the choice of datasource type.
o oracle.jdbc.pool.OracleConnection.PoolDataSource
o oracle.jdbc.xa.client.OracleXADataSource
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 14
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
10. Enter the Connection properties for the Datasource
o Key and Value
User: - User id to connect to the database.
Password: - the Password for the user id to connect to the database.
URL: - It is the database connection string.
o Connection Pooling: Based on the requirements we can optimize the number of connection and Pool settings.
SQL Engine: - Check the Vendor SQL for Oracle.
11. Enter the Datasource alias and click on Save.
Note: These steps can be used in Netweaver 7.0 also using NWA.
Systems on Netweaver Portal
JDBC System on Netweaver 7.0
1. Login to the portal
2. Navigate to system administration system configuration system landscape.
3. Create a folder e.g. JDBCSystem
4. Right click on the folder and select system from template
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 15
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
5. Select JDBC System and click on Next
6. Enter the System Name, ID and Click on Next
7. Click on open to enter the details for the system
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 16
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
8. From the property category dropdown select connection properties, enter the Connection URL and Driver Class Name for the System. Click on Save.
9. From the Display drop down select the system alias and define a system alias for the JDBC system.
10. Navigate to the User administration –identity management, select the user and define the user
mapping for the user.
11. Navigate to the JDBC system and perform a connection test.
NOTE: The steps remains same in Composite Environment, just the user interface has changed.
BI JDBC System
Refer to the following link for creating a BI JDBC System.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/6209b52e-0401-0010-6a9f-d40ec3a09424
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 17
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
Connecting to Visual Admin using P4 Port We need not require to the server to login to the visual admin every time a configuration is required. Following Steps describes how to connect to the server from standalone system.
1. Login to the server
2. Navigate to /usr/sap/<instance Name>/JC<instanceNO>/j2ee
3. Copy the admin folder to you local system.
4. Configure JAVA_HOME environment variable in your local system.
5. Open go.bat in the admin folder and change the JAVA_HOME if required.
6. Click on go.bat.
7. Click on New
8. Select the following checkbox and enter the Name of the connection, click next.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 18
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 19
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
9. Enter the following details
o User Name
o Server Name/Server IP
o P4 Port (In order to find the p4 port login to the system info and see the dispatcher section , P4 port usually is 50000+100*Instance No+4)
10. Click on Save.
11. Click on Connect.
12. Enter the user Id and Password to login to Visual Admin and access all the configuration.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 20
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
Note: Using the above steps we need not login to the server to access the visual admin to change the configuration.
Driver and Connection URL
Database Name
Driver Driver Class Connection URL
Oracle Classes12.jar oracle.jdbc.driver.OracleDriver
jdbc:oracle:<drivertype>:@<database>
MYSQL Server 2000
msbase.jar, msutil.jar, mssqlserver.jar
com.microsoft.jdbc.sqlserver.SQLServerDriver
jdbc:sqlserver://<host_name>:<port>;DatabaseName=<db_name>
MYSQL Server 2005
sqljdbc.jar com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc:sqlserver://<host_name>:<port>;database=<db_name>
MAX DB com.sap.dbtech.jdbc.DriverSapDB
jdbc:sapdb://<server>:<Port>/<database>
MYSQL mysql-connector-java-3.1.14-bin.jar
com.mysql.jdbc.Driver
jdbc:mysql://<host_name>:<port>/<database>
Sample code This is sample code which will return a connection from the Connection pool using the Datasource alias.
//This is a code sample block package com.infosys.database.connection; import java.sql.Connection; import javax.naming.InitialContext; import javax.sql.DataSource; /** * @author Pankaj_Prasoon * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class ConnectionManager { Connection connection=null; /* Obtains a connection object from the connection pool * specified in the Data Source in Visual Admin*/ public Connection getConnection(String aliasname){ try { InitialContext initialContext = new InitialContext(); // Initialize the context DataSource dataSource = (DataSource) initialContext.lookup(aliasname); connection=dataSource.getConnection(); //Obtain connection
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 21
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
connection.setAutoCommit(false); // Set Auto Commit to false. } catch (Exception e) { // TODO: handle exception } // Perform JNDI lookup for the datasource return connection; // Return conenction object to calling component }
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 22
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
Related Content SAP NOTE : 773401
http://help.sap.com/saphelp_nw04/helpdata/en/c0/3ad4d5cdc66447a188b582aad537d3/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c0/3ad4d5cdc66447a188b582aad537d3/frameset.htm
For more information, visit the Portal and Collaboration homepage.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 23
Step By Step Guide to Configure a JDBC Datasource and JDBC System in CE 7.1 and NW 7.0
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 24
Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.