The function is valid only for Java™ generation.
sqlLib.defineDatabaseAlias(
alias STRING in,
database STRING in)
The following example shows how you can maintain two separate database connections by using the sqlLib.defineDatabaseAlias() function.
// Connect to a database with alias "alias",
// which becomes the current connection.
defineDatabaseAlias( "alias", "database" );
connect( "alias", "user", "pwd" );
// Make two connections to the same database.
String db = "database";
defineDatabaseAlias( "alias1", db );
defineDatabaseAlias( "alias2", db );
connect( "alias1", "user", "pwd" );
connect( "alias2", "user", "pwd" );
// Another way to make two connections
// to the same database.
defineDatabaseAlias( "alias", "database" );
connect( "alias", "user", "pwd" );
connect( "database", "user", "pwd" );
// An alias is defined but not used. The second
// connect() does not create a new connection.
defineDatabaseAlias( "alias", "database" );
connect( "database", "user", "pwd" );
connect( "database", "user", "pwd" );
// Use of an alias (which is case-insensitive)
// when disconnecting.
defineDatabaseAlias( "alias", "database" );
connect( "aLiAs", "user", "pwd" );
disconnect( "ALIAS" );
// The next disconnect call fails because the
// connection is named "alias" not "database".
defineDatabaseAlias( "alias", "database" );
connect( "alias", "user", "pwd" );
disconnect( "database" );
// An alias can change. After the next call,
// "alias" refers to "firstDatabase"
defineDatabaseAlias( "alias", "firstDatabase" );
// After the next call,
// "alias" refers to "secondDatabase".
defineDatabaseAlias( "alias", "secondDatabase" );
// The last call would have failed
// if a connection were in place with "alias".
| Platform | Issue |
|---|---|
| JasperReports | You can use the database alias in the connectionName field of a ReportData variable. |
| VisualAge® Generator compatibility | You can use the database alias in a vgLib.connectionService() call. |