If the purpose of a resource binding is to specify the connection used for database access, the definition is called a SQL database binding.
If the same-name JNDI entry is already in place, your connection details supplement the existing entry. The fields that are available in the EGL deployment descriptor override the equivalent attributes in the existing entry. The override occurs even if you do not specify a value at all. However, if a JNDI attribute is not represented, the JNDI attribute in the existing entry is unaffected.
For details on defining an SQL database binding in the EGL deployment descriptor, see Adding an SQL database binding to the EGL deployment descriptor.
You enable a future connection to a database by declaring a connection variable. The connection itself occurs when you first run a database-access statement that uses the variable.
myDataSource SQLDataSource? { @Resource {uri="binding:"MyDatabaseBinding"} };
myJNDIDataSource SQLJNDIDataSource? { { @Resource {uri="binding:MyDatabaseJNDIBinding"} };
Your code interacts with either variable in the same way, and the use of the SQLDataSource type is sufficient in many cases. Here is an exception: if your subsequent logic uses the EGL isa operator to test whether a variable is of type SQLDataSource or SQLJNDIDataSource, you must use the SQLJNDIDataSource type for JNDI data sources and must use the SQLDataSource type for others.
myDataSource SQLDataSource? = Resources.getResource("binding:MyBinding"); myOtherDataSource SQLDataSource? = Resources.getResource("binding:file:MyFile#MyBinding2"); myJNDIDataSource SQLDataSource? = Resources.getResource("binding:MyJNDIBinding"); myOtherJNDIDataSource SQLJNDIDataSource? = Resources.getResource("binding:MyOtherJNDIBinding");
connectURL string = "jdbc:derby:SomeDB;create=true;"; properties Dictionary{user = "MyID", password = "MyPassword"}; myDataSource SQLDataSource? = new SQLDataSource(connectURL, properties);
connectURL string = "jdbc/myDataSource"; properties Dictionary{user = "MyID", password = "MyPassword"}; myJNDIDataSource SQLJNDIDataSource? = new SQLJNDIDataSource(connectURL, properties);
connectURL string = "jdbc/myDataSource"; myJNDIDataSource SQLJNDIDataSource? = new SQLJNDIDataSource(connectURL);
For a JNDI connection, if security detail is passed to a data source that operates under container-managed security, the result is not determined by the generated application or by the EGL runtime code. For details on what happens, see the documentation provided by the specific Java DataSource class in use.
For details on these capabilities, see the following page, which applies to both SQLDataSource and SQLJNDIDataSource: SQLDataSource external type.
For further details, see EGL support for relational databases.