oracle.jdbc.pool
Class OracleDataSource

oracle.jdbc.pool.OracleDataSource
Direct Known Subclasses:
OracleOCIConnectionPool

public class OracleDataSource
implements java.io.Serializable

A DataSource object is a factory for Connection objects. An object that implements the DataSource interface will typically be registered with a JNDI service provider. A JDBC driver that is accessed via the DataSource API does not automatically register itself with the DriverManager.

See Also:
Serialized Form

Constructor Summary
OracleDataSource()
           
 
Method Summary
 java.sql.Connection getConnection()
          Attempt to establish a database connection.
 java.sql.Connection getConnection(java.lang.String user, java.lang.String passwd)
          Attempt to establish a database connection.
 java.lang.String getDatabaseName()
          Get the name of the database set on this DataSource instance.
 java.lang.String getDataSourceName()
          Get the datasource name for this instance if set.
 java.lang.String getDescription()
          Get the Desciption of this data source.
 java.lang.String getDriverType()
          Get the Oracle JDBC driver type set for this datasource instance
 int getLoginTimeout()
          u Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
 java.io.PrintWriter getLogWriter()
          Get the log writer for this data source.
 java.lang.String getNetworkProtocol()
          Get the network protocol set.
 int getPortNumber()
          Get the port number on which server is listening for requests.
 oracle.jdbc.pool.Reference getReference()
           
 java.lang.String getServerName()
          Get the name of the server on which database is running.
 java.lang.String getTNSEntryName()
          Get the TNS entry name for this instance if set.
 java.lang.String getURL()
          Get the URL for this datasource.
 java.lang.String getUser()
          Get the user name for this datasource.
 void setDatabaseName(java.lang.String dsname)
          Set the name of a particular database on a server.
 void setDataSourceName(java.lang.String dsname)
          Set the DataSourceName.
 void setDescription(java.lang.String des)
          Set the Desciption for this data source instance.
 void setDriverType(java.lang.String dt)
          Set the JDBC driver type.
 void setLoginTimeout(int timeout)
          Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
 void setLogWriter(java.io.PrintWriter pw)
          Set the log writer for this data source.
 void setNetworkProtocol(java.lang.String np)
          Set the network protocol for the connections.
 void setPassword(java.lang.String pd)
          Set the password with which connections have to be obtained.
 void setPortNumber(int pn)
          Set the port number where a server is listening for requests.
 void setServerName(java.lang.String sn)
          Set the name of the Server on which database is running.
 void setTNSEntryName(java.lang.String dbname)
          Set the TNS entry name.
 void setURL(java.lang.String url)
          Set the URL from which connections have to be obtained.
 void setUser(java.lang.String user)
          Set the user name with which connections have to be obtained.
 

Constructor Detail

OracleDataSource

public OracleDataSource()
                 throws java.sql.SQLException
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException

Attempt to establish a database connection.

Returns:
a Connection to the database
Throws:
java.sql.SQLException - if a database-access error occurs.

getConnection

public java.sql.Connection getConnection(java.lang.String user,
                                         java.lang.String passwd)
                                  throws java.sql.SQLException

Attempt to establish a database connection.

Parameters:
user - the database user on whose behalf the Connection is being made
password - the user's password
Returns:
a Connection to the database
Throws:
java.sql.SQLException - if a database-access error occurs.

getLoginTimeout

public int getLoginTimeout()
u Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise it means that there is no timeout. When a DataSource object is created the login timeout is initially zero.
Returns:
the data source login time limit
Throws:
java.sql.SQLException - if a database access error occurs.

setLoginTimeout

public void setLoginTimeout(int timeout)

Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise it specifies that there is no timeout. When a DataSource object is created the login timeout is initially zero.

Parameters:
seconds - the data source login time limit
Throws:
java.sql.SQLException - if a database access error occurs.

setLogWriter

public void setLogWriter(java.io.PrintWriter pw)

Set the log writer for this data source.

The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a DataSource object is created the log writer is initially null, in other words, logging is disabled.

Parameters:
out - the new log writer; to disable, set to null
Throws:
java.sql.SQLException - if a database-access error occurs.

getLogWriter

public java.io.PrintWriter getLogWriter()

Get the log writer for this data source.

The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a DataSource object is created the log writer is initially null, in other words, logging is disabled.

Returns:
the log writer for this data source, null if disabled
Throws:
java.sql.SQLException - if a database-access error occurs.

setTNSEntryName

public void setTNSEntryName(java.lang.String dbname)
Set the TNS entry name. Works only for JDBC OCI driver. Assumed that client side Oracle in installed and TNS_ADMIN env variable is set. If URL is set, this property will be ignored.

Parameters:
dbname - tns entry name

getTNSEntryName

public java.lang.String getTNSEntryName()
Get the TNS entry name for this instance if set. Returns null if not set.
Returns:
TNS entry name

setDataSourceName

public void setDataSourceName(java.lang.String dsname)
Set the DataSourceName. Users need not set this as it will be set set automatically depending upon the instance created. Returns OracleDataSource for an OracleDataSource instance. Returns OracleXADataSource for an OracleXADataSource instance.

Parameters:
dsname - DataSource Name to be set.

getDataSourceName

public java.lang.String getDataSourceName()
Get the datasource name for this instance if set. Returns null if not set.
Returns:
DaraSource name

getDatabaseName

public java.lang.String getDatabaseName()
Get the name of the database set on this DataSource instance.
Returns:
database name set on this instance or null if not set.

setDatabaseName

public void setDatabaseName(java.lang.String dsname)
Set the name of a particular database on a server. In Oracle's jargon this is called SID (System Identifier).

If URL is set, this property will be ignored.

Parameters:
dsname - database name to be set.

setServerName

public void setServerName(java.lang.String sn)
Set the name of the Server on which database is running. If URL is set, this property will be ignored.

Parameters:
sn - server/host name to be set.

getServerName

public java.lang.String getServerName()
Get the name of the server on which database is running.
Returns:
server name set on this instance or null if not set.

setURL

public void setURL(java.lang.String url)
Set the URL from which connections have to be obtained. If URL is set all other properties like databasename, servername, portNumber, network protocol, tnsentry, and driver Type will be ignored.

Parameters:
url - URL to be set.

getURL

public java.lang.String getURL()
                        throws java.sql.SQLException
Get the URL for this datasource. Will return the default value "jdbc:oracle:oci8:@" if not set before.


setUser

public void setUser(java.lang.String user)
Set the user name with which connections have to be obtained.

Parameters:
user - Username to be set.

getUser

public java.lang.String getUser()
Get the user name for this datasource. Will return the default value ("scott") if not set before.

setPassword

public void setPassword(java.lang.String pd)
Set the password with which connections have to be obtained. The default value is "tiger".

Parameters:
pd - Passowrd to be set.

getDescription

public java.lang.String getDescription()
Get the Desciption of this data source.
Returns:
Description that was set or will return null if not set.

setDescription

public void setDescription(java.lang.String des)
Set the Desciption for this data source instance.
Parameters:
des - Desciption to be set.

getDriverType

public java.lang.String getDriverType()
Get the Oracle JDBC driver type set for this datasource instance
Returns:
Driver Type that was set or null if not set.

setDriverType

public void setDriverType(java.lang.String dt)
Set the JDBC driver type. Possible values are thin, oci8, and kprb. If URL is set, this property will be ignored.

If set to kprb, nothing else is needed to open a connection. This is meant for Server side JDBC driver when running inside server.

If set to thin, serverName, portNumber and databaseName are need to open a connection.

If set to oci, and network protocol is set to IPC or TNSEntryName is set then nothing else is needed. If not, serverName, portNumber and databaseName have to be provided.

Parameters:
dt - Driver Type tp be set.

getNetworkProtocol

public java.lang.String getNetworkProtocol()
Get the network protocol set.
Returns:
network protocol that was set or null if not.

setNetworkProtocol

public void setNetworkProtocol(java.lang.String np)
Set the network protocol for the connections. Default is "tcp". Can be set to all possible protocols Net8 supports. Only needed for JDBC OCI driver.

Parameters:
np - set the network protocol to be used.

setPortNumber

public void setPortNumber(int pn)
Set the port number where a server is listening for requests. Not required when URL is set.
Parameters:
pn - port number on which server is listening

getPortNumber

public int getPortNumber()
Get the port number on which server is listening for requests.
Returns:
port number if set or null if not set.

getReference

public oracle.jdbc.pool.Reference getReference()
                                        throws oracle.jdbc.pool.NamingException