This web log explains you how to deploy a new custom data source in SAP NetWeaver CE 7.1 to enable an application to get access to an external database other than the system databse of the SAP NW CE Application Server.
For an application to access an external database we have to deploy a data source for that database.But to deploy a datasource , we need to deploy the relavant JDBC driver for that data base.
The process of enabling your application to get acces to an external database requires the following steps:
- Deploying the Data Source
- Deploying the Data Source Aliases
The known ways to perform the above steps are:
- Throgh the web based SAP Net Weaver Administrative tool.This is the easier way to deploy a new custom data source.
- Throuh the AS Java Telnet tool.This is a command line tool.You have to use DBPOOL shell command group to manage the data sources.
- As a part of the Java EE Application, using the SAP NW Dev Studio.
The rest of this blog will guide you to establish a connection with an external database(eg: MYSQL) using the Web based SAP NW Administrative tool.
SAP NW Administrative tool:
To start the SAP NetWeaver Administrator, enter the following URL in a Web browser: http://<host>:<port>/nwa, where:00. For example, if the instance number of the Java instance is 60, the HTTP port is 56000.
Select Configuration Management
>Infrastructure> Application Resources function
*Procedure </p><p>1 Deploying a new JDBC driver:To create a Data Source, you must first deploy a compatable JDBC driver.This has to be downloaded from the vendor’s web site.You can deploy either JDBC 1.x or JDBC 2.0-compliant driver.When you first log on to the system there is already a defined driver. This is the system driver. You cannot remove this driver. </p><p>+Choose Create New Resource->Deploy New JDBC Driver. +The new JDBC driver creation window opens.</p><ol><li>Enter an arbitrary name for the driver which will be used while creating the data source..</li><li>Choose ‘Add New driver File’.</li><li>Browse the driver file in the system.</li><li>Choose OK.</li></ol><p>!https://weblogs.sdn.sap.com/cs/blank/edit/wlg/|height=1|alt=|width=1|src=https://weblogs.sdn.sap.com/cs/blank/edit/wlg/|border=0!!../../../../weblogs/images/251842966/image2.JPG|height=197|alt=image|align=middle|width=396|src=../../../../weblogs/images/251842966/image2.JPG|border=0!</p><p> </p><p>On successfull deployment ,success message will be displayed..</p><p>2 Deploying a new Custom Data Source.*
Choose Create New Resource->Deploy New JDBCCustom Data Source.The new JDBC Custom DataSource creation window opens.
Specify the name of the application that needs to be associated to the JDBC DataSource in the Application Name field. The system uses this name for the configuration that holds the JDBC DataSource.
Specify a unique name for the JDBC DataSource in the DataSource Name field. It is used when you look up the JDBC DataSource in the naming.
Select a driver from the Driver Name dropdown list box. Choose the driver that you have created in the previous step.
Select the SQL type support from the SQL Engine dropdown list box.
In the context of the SAP NetWeaver Application Server Java, you can use Open SQL, Native SQL or Vendor SQL as the SQL engine types in your Data Source definition.
- Vendor SQL can be used with any database that provides a JDBC-compliant driver.
- Native SQL is a wrapper for the vendor-specific JDBC driver and provides important enhancements such as SQL trace and statement pooling. However, it can be used only with databases supported by SAP: Oracle 9.2 and 10.2, MSSQL 8, MaxDB 7.x, and DB2 for Linux, UNIX, Windows, versions 9.x and 8.x.
- Open SQL is an SAP-proprietary database abstraction layer, which is designed to provide portability across various database platforms and performance optimizations through client-side data buffering.
But ,if you want to connect your application to existing tables in an external database, then you should consider using a custom DataSource with Native SQL or Vendor SQL access type. Open SQL is not an option in this case, since it only works using the System DataSource and connecting to the system database schema.So choose Vendor SQL From the SQL Engine type drop down list.
Select the transaction isolation level from the Isolation Level dropdown list box.
Select the JDBC type support from the JDBC Version dropdown list box. Depending on the JDBC version you choose, you have to enter the following additional information:
- If you choose JDBC 1.x support, you have to enter a driver class name, database URL, user name, and password.
- If you choose JDBC 2.0 support, you have to enter the data source type, ConnectionPool DataSource or XA DataSource. You must also enter the class name for the corresponding implementation provided by the driver and the vendor-specific initialization properties (serverName, portNumber, and so on).
You can define Datasource alias(es)(eg:MYSQLDS_DS1_ALIAS1) for your datasource with JDBC Data Sources Aliases tab.A Data Source alias is a logical name mapped to the name of a real Data Source available in the system. You use the Data Source alias in your application code to connect to the underlying Data Source.
Finally,select Save. The newly created DataSource appears in the list of JDBC Custom DataSources.
Now you can use your DataSource alias in your application code to connect to the underlying Data Source.
ds = (DataSource) ctx.lookup(“jdbc/MYSQLDB_DS1_ALIAS1”);
If you want you can view your data source aliases in the naming tree of the JNDI Registry using the JNDI Browser.
To open JNDI Browser Choose Problem Management–>JNDI Browser in the NW Administrative tool.
[SAP Help Documentation for deploying a Data Source | http://help.sap.com/saphelp_nwce10/helpdata/en/45/07d2eeea3e0485e10000000a155369/content.htm]
[SAP Help Documentation for JNDI Browser | http://help.sap.com/saphelp_nwce10/helpdata/en/45/27b87fd3a96d95e10000000a114a6b/content.htm]