![]() |
|
A JDBC Connection Factory Resource is used to obtain connections from the given driver or XA datasource implementation. No connection pooling is involved in this process.
Different versions of the same driver can be used in the same instance of a running server. For example, you can create a JDBC Connection Factory with OracleDriver version 3, and create another one with version 4. This is possible since the driver jars are not picked up from a common location, but are taken from the path specified in the input box. In case you do not specify the path, the Server attempts to pick up the jars from the \lib\ext directory under the Server installation directory, or from the system classpath.
Whatever the type of Connection Factory, make sure that the driver is present in the classpath. The Console issues a warning message if the driver is not found. To add the driver to the classpath, either place the required .jars in the directory, or add the classpath to the classpath variable of the .bat or .sh setup file.
You can configure a Connection Factory using resource-config.xml by adding a connection-factory tag under the connection-factories tag. The resource-config.xml looks as below:
<resource-service>
<resources>
<default-resources> <default-resources>
<datasources> <datasources>
<connection-factories>
<connection-factory name="CLOUDSCAPE_CF1" description="CloudscapeCF" classname="COM.cloudscape.core.JDBCDriver"
url="jdbc:cloudscape:../samples/sample_db" authorized-by="Container">
<login-parameters user="" password="" mask-password="false"/>
<connection-factory>
<connection-factories>
<mail-resources> <mail-resources>
<url-resources> <url-resources>
<jms-adapters> <jms-adapters>
<resources>
</resource-service>
The mandatory fields for the connection-factory tag are connection-factory name, classname, url, and authorized-by. If the authorized-by field is specified as container, you also need to provide values for the user and password attributes, else blank strings will be taken as values for these fields.
JDBC resources can also be added using the command prompt. To invoke the resource shell, type the command ressh on the Server command prompt. To add a JDBC Connection Factory, type add_jdbc_cf. There are two ways to add a Connection Factory using the command.
To use the interactive mode, enter add_jdbc_cf, and press Enter. This asks for all the required fields one after the other. No special flag is required for this mode.
Enter the following values needed for the command resourceadmin:> add_jdbc_cf
resourceadmin> - jndi name * #my_jdbc_cf resourceadmin> - class name * #oracle.jdbc.driver.OracleDriver resourceadmin> - url * #jdbc:oracle:thin:@db1.pramati.com:1521:db1 resourceadmin> - user name #scott resourceadmin> - password #tiger resourceadmin> - classpath # resourceadmin> - authorizedBy #container resourceadmin> - test [true] # Adding JDBC Connection Factory my_jdbc_cf Creating JDBC Connection Factory my_jdbc_cf Connection Factory [my_jdbc_cf] started Created JDBC Connection Factory [my_jdbc_cf] successfully Added JDBC Connection Factory [my_jdbc_cf]
Note: Fields followed by * are mandatory. You can press Enter for default values shown. Typing 'q' and pressing Enter at any point cancels the current command.
To use the non-interactive mode, enter add_jdbc_cf. All the required attributes, such as JNDI name, Class Name, and the URL in this case, have to be specified. All optional attributes have default values that can be modified. There are three ways to specify the fields:
add_jdbc_cf jndiName=my_jdbc_cf className=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@db1.pramati.com:1521:db1add_jdbc_cf my_jdbc_cf oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@db1.pramati.com:1521:db1add_jdbc_cf -jndiName my_jdbc_cf -className oracle.jdbc.driver.OracleDriver -url jdbc:oracle:thin:@db1.pramati.com:1521:db1Once you have the Resource Service MBean, call the JDBCResourceMBean by entering JDBCResourceMBean jdbcResource= resourceServiceMBean.getJDBCResourceMBean();
After this, call the createConnectionFactory method on this MBean.
/** * Creates a new connection factory. * * @param jndiName JNDI name of the connection factory. * * @param className Full class name of implementation of any of the following * interfaces, which is usually provided by the database vendor. ** java.sql.Driver* * @ param jar: Full path to the jars from which the className has to be * picked, this has to be mentioned incase the className is not mentioned in * the system classpath. * * @param connectionFactoryProps: A set of properties for consumption of * underlying driver specified in className parameter. If className parameter * is of type
* javax.sql.DataSource
* javax.sql.XADataSource
* javax.sql.ConnectionPoolDataSource
*java.sql.Driverfollowing properties may make * sense: ** {@link JDBCResourceMBean#USER user} * {@link JDBCResourceMBean#PASSWORD password} * {@link JDBCResourceMBean#URL url} * Any other database driver specific property(ies) ** * If className parameter is of other types then following is the list of * standard properties and it can include any driver specific properties. ** {@link JDBCResourceMBean#DATABASE_NAME databaseName} * {@link JDBCResourceMBean#DATASOURCE_NAME dataSourceName} * {@link JDBCResourceMBean#DESCRIPTION description} * {@link JDBCResourceMBean#NETWORK_PROTOCOL networkProtocol} * {@link JDBCResourceMBean#PASSWORD password} * {@link JDBCResourceMBean#PORT_NUMBER portNumber} * {@link JDBCResourceMBean#ROLE_NAME roleName} * {@link JDBCResourceMBean#SERVER_NAME serverName} * {@link JDBCResourceMBean#USER user} * {@link JDBCResourceMBean#LOGIN_TIMEOUT_PERIOD loginTimeoutPeriod} ** * @param isAuthByServer: Iftruethe sign-on to database will be * done by the container on the behalf of user for obtaining database connections. * Iffalseapplication has to provide sign-on info * (user name/password) at the time of obtaining the connection. * * @param test: Whether to test the connection factory at the time of * instantiation (applicable only if isAuthByServer is true) * @throws ResourceException: If some problem occurs in connection factory * creation. For example, JNDI name may already be in use. */ public void createConnectionFactory(String jndiName, String className, String jars, DataSourceProperty[] connectionFactoryProps, boolean isAuthByServer, Boolean test)throws ResourceException;
To configure a Connection Factory Resource using the Console, select Configure > Resources. This displays the Resources screen. If there are JDBC Connection Factory Resources added earlier, the following details are displayed:
Table 1: Details about Connection Factory
| Fields | Description |
|---|---|
| Name | The JNDI name of the Connection Factory. This is a mandatory field and should be unique. |
| Driver | The driver used by the Connection Factory. |
| Authorized by Server | This uses a value of True or False. True indicates that the Server has authorized the resource as the login details have been provided at the time of creation. |
| Properties | Use Edit to modify and view the existing properties for the Connection Factory Resource. |
The following actions can be performed on a JDBC Connection Factory:
To add a Connection Factory, click Add under JDBC Connection Factory, and specify the following information:
Table 2: Details needed to add a JDBC Connection Factory
| Fields | Options | Description |
|---|---|---|
| Driver/XA Datasource Class | - | An XA datasource provides connections that can participate in distributed transactions. Selecting a driver type automatically provides values for the Class and the Connection URL fields. |
| - | Oracle DB | For details about the drivers used, refer to Table 3 below. |
| - | SQL DB | For details about the drivers used, refer to Table 3 below. |
| - | XA datasource implementation | For XA data resources, the vendor provides the class that implements javax.sql.XADataSource interface. JDBC vendors that support distributed transactions must implement these interfaces. If Database is IBM Informix, enter the class as com.informix.jdbcx.IfxXADataSource. If Database is Oracle, enter the class as oracle.jdbc.xa.client.OracleXADataSource |
| - | Others | You can use other drivers, or other XA datasource implementations. You must provide appropriate values for the class and the Connection URL fields. |
| Class | - | JDBC driver or the XA datasource implementation class name is mandatory and is provided by the database vendor. It is used to access the database. Pramati Server supports JDBC 2.0 Drivers. Selecting the driver in the field above automatically displays the associated class. |
| Connection URL | - | Refers to the location. If Database is Cloudscape, type URL as jdbc:cloudscape: |
| Name | - | Clients locate a resource by using the JNDI name. It is used as a reference to obtain all information about the resource and is unique in the Server name space. Connection Factory JNDI name is mandatory. |
| Classpath | - | This option allows you to specify the location of the driver/implementation classes or jars. Different versions of the same driver can be used in the same instance of a running Server. For example, you can create a JDBC Connection Factory with OracleDriver version 3, and create another one with version 4. This is possible since the driver jars are not picked up from a common location, but are taken from the path specified in the input box. An example classpath might be C:\JDBCDrivers\Oracle\ojdbc14.jar. In case you do not specify the path, the Server attempts to pick them up from the \lib\ext directory under the Server installation directory, or from the system classpath. |
| Authorized by | - | Provides the authentication required to access the database. The application or container can provide authentication information. The authorization mode can be predefined. |
| - | Application | This field does not require you to supply the user name and password. They will be provided by the application while connecting to the Connection Factory. |
| - | Container | This field requires you to supply the user name and password at the time of creation. |
| - | - | User name: required to connect to the database. |
| - | - | Password: required to authenticate access. |
When the URL provided is incorrect, a message Network adaptor could not establish a connection is displayed. Appropriate messages are displayed when the user name or password is incorrect.
Note: An XA datasource that has been authored by the application does not require user name and password.
Table 3: Drivers supported by Pramati Server
| Name of Database | Name of Driver |
|---|---|
| Oracle database | oracle.jdbc.driver.OracleDriver |
| Merant's Oracle driver | com.merant.datadirect.jdbc.oracle.OracleDriver |
| Informix JDBC driver | com.informix.jdbc.IfxDriver |
| Merant's Informix JDBC driver | com.merant.datadirect.jdbc.informix.InformixDriver |
| Cloudscape Embedded driver | com.cloudscape.core.JDBCDriver |
| Cloudscape RMI driver | com.cloudscape.core.RmiJdbcDriver |
| Merant's SQL Server Driver | com.merant.datadirect.jdbc.sqlserver.SQLServerDriver |
| JTurbo driver for SQL Server | com.ashna.jturbo.driver.Driver |
| MySQL JDBC Driver | com.mysql.jdbc.Driver |
In case you select XA datasource as the driver, you will need to specify the following properties:
Table 4: Properties to be specified for XA datasources
| Fields | Description |
|---|---|
| JNDI Name | The JNDI name specified earlier is displayed here. This is not editable. |
| Class Name | The class name specified earlier is displayed here. This is not editable. |
| Properties | Other optional properties required by the driver, or XA datasource are displayed here. For every XA datasource, there are nine standard properties. |
| Property Type | This field displays the property type. This is not editable. |
| Property Value | The value of the property is to be specified in this field. |
The properties for an XA datasource may be standard or driver-specific. Depending on the driver selected earlier, the Console displays the standard properties as well as the proprietary properties accepted by the driver. Their values are optional.
Note: Certain vendor-specific properties may also need to be specified. These must be entered in the Property column. For more information about the Oracle datasource class, visit http://technet.oracle.com/doc/oracle8i_816/java.816/a81354/connpoc1.htm. These properties follow the JavaBeans design pattern.
Clicking Next>> displays the Step 2 for creating the JDBC Connection Factory.
Clicking Properties against the JNDI Connection Factory Name displays the properties with which the connection factory was created. These include:
Whether or not you can modify the properties, depends on the driver class selected.
Select the check box for the Connection Factory Resource to be deleted on the Resources page and click Delete. This deletes the selected resource.
Related Topics:
| © Pramati Technologies 2007 | Runs on Pramati Server | Feedback | Legal |