ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzamy_5.4.0.1/50/program/datalkrr.htm

41 lines
2.6 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
<title>Looking up data sources with resource references for relational access</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h6><a name="datalkrr"></a>Looking up data sources with resource references for relational access</h6>
<p>Using a resource reference to access your data source or connection factory is required when running in WebSphere Application Server - Express. Some of the reasons follow:</p>
<ul>
<li><p>If a data source is looked up directly, the connection gets all default properties for the missing resource reference. For example, the sharing-scope is a shareable connection resulting in the possibility that the physical connection is the same each time the connection is requested from the data source. This situation can cause a multitude of problems if you expect unshareable connections.</p></li>
<li><p>It relieves the programmer from having to know the name of the actual data source at the target application server. </p></li>
<li><p>You can set the default isolation level for the data source through resource references. With no resource reference you get the default for the JDBC driver you use. For more information, see <a href="dataisol.htm">Isolation level and resource reference</a>.</p></li>
</ul>
<p>Use a resource reference (resource-ref) for looking up a data source through the standard Java Naming and Directory Interface (JNDI) naming interface. The JNDI name defined in the resource-ref is a logical name of the data source. Have your application use this JNDI name to look up a data source instead of using the JNDI name that is defined on the data source.</p>
<p>Later, you can substitute the real name during installation of the application EAR file onto the server. </p>
<p>For example, assume that you use a DataSource jdbc/Section as illustrated in the code below.</p>
<pre>import javax.sql.*;
import javax.rmi.*;
...
DataSource specificDataSource = (DataSource) PortableRemoteObject.narrow(
(new InitialContext()).lookup(&quot;java:comp/env/jdbc/Section&quot;), DataSource.class);</pre>
<p>Using the WebSphere Development Studio Client, specify the name (jdbc/Section) as the resource reference. If you know the name of the DataSource, specify it also. For more information, see the WebSphere Development Studio Client Help.</p>
</body>
</html>