Class Hierarchy All Classes All Fields and Methods

 

Class com.ibm.db.beans.DBConnectionSpec

java.lang.Object
        com.ibm.db.beans.DBConnectionSpec

public class DBConnectionSpec
implements Serializable
extends Object

This bean contains the specifictions for a database connection. You set the properties of this bean before actually connecting to the database. Those properties will determine how the database connection is established (such as using a DataSource or using the DriverManager).

You associate a statement with a DBConnectionSpec via the DBStatement.setConnectionSpec() method. The statement will then use the specification in the DBConnectionSpec to obtain a connection. Setting a statement's DBConnectionSpec is an alternative to setting the connection properties directly on the statement. It is useful if more than one statement will be using the same connection specifications.

The DBConnectionSpec only contains connection properties that cannot be changed after a connection has been obtained. You set connection properties (like autoCommit and transactionIsolation) that can be changed after a connection has been obtained directly on the statement.

If a DataSourceName is specified, a reference to the DataSource found through the JNDI lookup when a connection is obtained is saved in the DBConnectionSpec. If the DBConnectionSpec is used again to obtain a connection, the connection can be obtained from the DataSource without requiring a JNDI lookup again.

If two beans share the same DBConnectionSpec, it does not mean that they will share the same database connection. To make two beans share the same connection use the DBStatement.shareConnectionWith() method.

Constructor Index
Constructor Description
DBConnectionSpec() The default constructor

Method Index
Method Description
String getDataSourceName() Gets the JNDI name of the javax.sql.DataSource to use when opening a database connection.
String getDriverName() Gets the class name of the JDBC driver that will automatically be loaded and registered for you before using the DriverManager to open a database connection.
String getInitialContextFactory() Gets the class name of the InitialContextFactory that will be used to locate a javax.sql.DataSource.
Object getInternalUseObject(int) For Internal Use only.
PrintWriter getLogWriter() Gets the PrintWriter being used to log any error information written by this bean.
String getPassword() Returns a String of asterisks (*) the length of the password used to create a database connection.
boolean getPromptUID() Gets the class name of the InitialContextFactory that will be used to locate a javax.sql.DataSource.
Properties getProperties() Returns the connection properties for this DBConnectionSpec.
String getProviderUrl() Gets the URL of the machine where the naming service should look for a javax.sql.DataSource.
String getUrl() Gets the url of the database to connect to using the DriverManager.
String getUsername() Gets the user name used to create a database connection.
void setDataSourceName(String) Specifies the name of a javax.sql.DataSource to use when opening a database connection, and clears any value previously set for the url property.
void setDriverName(String) Specifies the class name of a JDBC driver that will automatically be loaded and registered for you before using the DriverManager to open a database connection.
void setInitialContextFactory(String) Specifies the class name of the InitialContextFactory that will be used to locate a javax.sql.DataSource.
void setInternalUseObject(Object) For Internal Use only.
void setLogWriter(PrintWriter) Provides the PrintWriter that will be used to log any error information written by this bean.
void setPassword(String) Sets the password used to create a database connection.
void setPassword(String, boolean) Sets the password used to create a database connection.
void setProperties(Properties) Sets the connection properties to use when establishing a connection.
void setProviderUrl(String) Specifies the URL of the machine where the naming service should look for a javax.sql.DataSource.
void setUrl(String) Specifies the url of the database to connect to using the DriverManager, and clears any value previously set for the dataSourceName property.
void setUsername(String) Sets the user name used to create a database connection.

 

Constructors

 

DBConnectionSpec

public DBConnectionSpec() 

The default constructor

 

Methods

 

getDataSourceName

public String getDataSourceName() 

Gets the JNDI name of the javax.sql.DataSource to use when opening a database connection. Users should set either the url or dataSourceName property.

When a connection is established, either the dataSourceName property or the url property is used, whichever was specified most recently. If the dataSourceName is used, a connection is established via a javax.sql.DataSource object. If the url is used, a connection is established via the Driver Manager.

 

getDriverName

public String getDriverName() 

Gets the class name of the JDBC driver that will automatically be loaded and registered for you before using the DriverManager to open a database connection.

If this property is null or an empty string, no driver will be automaticaly loaded and registered. It may still be possible to connect via the DriverManager if an appropriate driver has been loaded and registered independently of this bean.

This property is only used if the url property is not null. If the url property is null, then this field is ignored and the connection is obtained using the DataSource specified in the dataSourceName property.

 

getInitialContextFactory

public String getInitialContextFactory() 

Gets the class name of the InitialContextFactory that will be used to locate a javax.sql.DataSource.

If this property is null, the default InitialContextFactory identified by the java.naming.factory.initial property in your java environment will be used.

This property is only used if the dataSourceName property is not null. If the dataSourceName property is null, then this field is ignored and the connection is obtained using the DriverManager.

 

getInternalUseObject

public Object getInternalUseObject(int aType) 

For Internal Use only. Do not use.

 

getLogWriter

public PrintWriter getLogWriter() 

Gets the PrintWriter being used to log any error information written by this bean.

The default log writer logs to the Java console. When this property is set to null, no information is logged.

 

getPassword

public String getPassword() 

Returns a String of asterisks (*) the length of the password used to create a database connection. The actual password is not returned so that the return value of this method can be displayed in a GUI without compromising security.

 

getPromptUID

public boolean getPromptUID() 

Gets the class name of the InitialContextFactory that will be used to locate a javax.sql.DataSource.

If this property is null, the default InitialContextFactory identified by the java.naming.factory.initial property in your java environment will be used.

This property is only used if the dataSourceName property is not null. If the dataSourceName property is null, then this field is ignored and the connection is obtained using the DriverManager.

 

getProperties

public Properties getProperties() 

Returns the connection properties for this DBConnectionSpec. Properties specify keyword/value pairs other than username and password required for connecting to the database. Username and password can be set separately.

 

getProviderUrl

public String getProviderUrl() 

Gets the URL of the machine where the naming service should look for a javax.sql.DataSource.

If this property is null, the naming service will look on the local host.

This property is only used if the dataSourceName property is not null. If the dataSourceName property is null, then this field is ignored and the connection is obtained using the DriverManager.

 

getUrl

public String getUrl() 

Gets the url of the database to connect to using the DriverManager. The default value is null.

When a connection is established, either the dataSourceName property or the url property is used, whichever was specified most recently. If the dataSourceName is used, a connection is established via a javax.sql.DataSource object. If the url is used, a connection is established via the Driver Manager.

 

getUsername

public String getUsername() 

Gets the user name used to create a database connection.

 

setDataSourceName

public void setDataSourceName(String aName) 

Specifies the name of a javax.sql.DataSource to use when opening a database connection, and clears any value previously set for the url property.

When a connection is established, either the dataSourceName property or the url property is used, whichever was specified most recently. If the dataSourceName is used, a connection is established via a javax.sql.DataSource object. If the url is used, a connection is established via the Driver Manager.

 

setDriverName

public void setDriverName(String aDriverName) 

Specifies the class name of a JDBC driver that will automatically be loaded and registered for you before using the DriverManager to open a database connection. The name must be fully qualified with the package containing the driver. For example, the DB2 application JDBC driver is COM.ibm.db2.jdbc.appDB2Driver.

If this property is null or an empty string, no driver will be automaticaly loaded and registered. It may still be possible to connect via the DriverManager if an appropriate driver has been loaded and registered independently of this bean.

This property is only used if the url property is not null. If the url property is null, then this field is ignored and the connection is obtained using the DataSource specified in the dataSourceName property.

 

setInitialContextFactory

public void setInitialContextFactory(String aInitialContextFactory) 

Specifies the class name of the InitialContextFactory that will be used to locate a javax.sql.DataSource. The name must be fully qualified with the package containing the class. For example, the InitialContextFactory for the WebSphere naming service is com.ibm.ejs.ns.jndi.CNInitialContextFactory.

If you set this property to null, the default InitialContextFactory identified by the property java.naming.factory.initial in your java environment will be used.

This property is only used if the dataSourceName property is not null. If the dataSourceName property is null, then this field is ignored and the connection is obtained using the DriverManager.

 

setInternalUseObject

public void setInternalUseObject(Object aDataSource) 

For Internal Use only. Do not use.

 

setLogWriter

public synchronized void setLogWriter(PrintWriter out) 

Provides the PrintWriter that will be used to log any error information written by this bean.

If you do not explicitly use this method to provide a PrintWriter, information is logged by default to the Java console. If you wish to have no information logged, you can provide a null value here. If you wish to have log information for this bean and log information for your database written to the same place, provide the same PrintWriter for both the DriverManager.setLogWriter() method and this method.

 

setPassword

public void setPassword(String aPassword) 

Sets the password used to create a database connection. If the value passed in is a String of asterisks (*) the length of the current password, the value is not set. It is assumed in this case that a property editor has used getPassword() to get the password shape, and has used that same value to set the password, without real intent to change the password.

 

setPassword

public void setPassword(String aPassword,
                        boolean decode) throws DBException

Sets the password used to create a database connection. If requested, the password is decoded before it is saved.

 

setProperties

public void setProperties(Properties properties) 

Sets the connection properties to use when establishing a connection. Use properties to specify keyword/value pairs other than username and password required for connecting to the database. Username and password can be set separately.

 

setProviderUrl

public void setProviderUrl(String aProviderUrl) 

Specifies the URL of the machine where the naming service should look for a javax.sql.DataSource.

If you set this property to null, the naming service will look on the local host.

This property is only used if the dataSourceName property is not null. If the dataSourceName property is null, then this field is ignored and the connection is obtained using the DriverManager.

 

setUrl

public void setUrl(String aUrl) 

Specifies the url of the database to connect to using the DriverManager, and clears any value previously set for the dataSourceName property. The default value is null.

When a connection is established, either the dataSourceName property or the url property is used, whichever was specified most recently. If the dataSourceName is used, a connection is established via a javax.sql.DataSource object. If the url is used, a connection is established via the Driver Manager.

To connect using the Driver Manager, either insure that a driver that accepts the url has been loaded and registered, or use the setDriverName method to cause such a driver to be automatically loaded and registered for you.

 

setUsername

public void setUsername(String aName) 

Sets the user name used to create a database connection.

Class Hierarchy All Classes All Fields and Methods