Nonstop Database, HiRDB Version 9 UAP Development Guide

[Contents][Index][Back][Next]

18.6.1 DataSource interface

For details and usage information about the methods provided by the DataSource interface, see the JDBC documentation. This section shows the DataSource interface methods that are supported by the JDBC driver.

Organization of this subsection
(1) Methods
(2) Package and class names

(1) Methods

The following table lists the methods of the DataSource interface.

Table 18-58 DataSource interface methods

Subsection Method Function
(a) getConnection() Attempts to connect to the database using the connection information set in the data source.
(b) getConnection(String username,String password) Attempts to connect to the database using the connection information set in the data source.
(c) getLoginTimeout() Returns the value specified by the setLoginTimeout method.
(d) getLogWriter() Acquires the DataSource object's log writer.
(e) setLoginTimeout(int seconds) Specifies the maximum amount of time (in seconds) to wait for the connection to the database to be completed.
(f) setLogWriter(PrintWriter out) Sets a log writer for the DataSource object.
(a) getConnection()

Function
Attempts to connect to the database using the connection information set in the data source.

Format
 
public synchronized Connection getConnection() throws SQLException
 

Arguments
None.

Return value
Connection object

Functional detail
This method uses the connection information that has been set in the DataSource object to connect to the HiRDB server, and returns a connected Connection object. For details about the specification method priorities for the user name and password, see 18.11 Connection information priorities.

Exceptions
The JDBC driver throws an SQLException in the following cases:
  • A database access error occurred.
  • Specified connection information is invalid.
    For details about the conditions under which the connection information items become invalid, see 18.2.2(1) URL syntax and 18.2.2(2) User properties.
(b) getConnection(String username, String password)

Function
Attempts to connect to the database using the connection information set in the data source.

Format
 
public synchronized Connection getConnection(String username, String password) throws SQLException
 

Arguments
String username
User name used to establish connection
String password
Password used to establish connection

Return value
Connection object

Functional detail
This method uses the information specified in the arguments and the connection information that has been set in the DataSource object to connect to the HiRDB server, and returns a connected Connection object.
When the null value is set in the username or password argument it means that the argument with the null value is not being used to set the user name or password. When the password argument contains a character string with a length of 0 it means that no password is specified. When a user ID is specified in both the username argument and ConnectionProperty, the username argument takes precedence. Similarly, the password argument takes precedence for a password specification. For details about the specification priorities when the username and password arguments are not specified, see 18.11 Connection information priorities.

Exceptions
The JDBC driver throws an SQLException in the following cases:
  • A database access error occurred.
  • The specified connection information is invalid.
    For details about the conditions under which the connection information items become invalid, see 18.2.2(1) URL syntax and 18.2.2(2) User properties.
  • The user name specified in the username argument is a character string with a length of 0.
(c) getLoginTimeout()

Function
Returns the value specified by the setLoginTimeout method.

Format
 
public synchronized int getLoginTimeout()
 

Arguments
None.

Return value
int type:
Value specified by the setLoginTimeout method. If no value has been specified by setLoginTimeout, this method returns 0.

Exceptions
None.
(d) getLogWriter()

Function
Acquires the DataSource object's log writer.

Format
 
public synchronized PrintWriter getLogWriter() throws SQLException
 

Arguments
None.

Return value
This method returns the log writer for the PrdbDataSource object. If no log writer has been set, the method returns the NULL value.

Exceptions
None.
(e) setLoginTimeout(int seconds)

Function
Specifies the maximum amount of time (in seconds) to wait for the connection to the database to be completed.

Format
 
public synchronized void setLoginTimeout(int seconds) throws SQLException
 

Arguments
int seconds
Maximum connection wait time (seconds)

Return value
None.

Functional detail
This method is used when a physical connection is established with the HiRDB server in order for the getConnection method to acquire a Connection object. If 0 is specified or setLoginTimeout is not executed, the value specified in PDCONNECTWAITTIME is assumed as the maximum amount of time to wait for the HiRDB server to be physically connected.

Exceptions
If the seconds argument value is less than 0 or is greater than 300, the method throws an SQLException.
(f) setLogWriter(PrintWriter out)

Function
Sets a log writer for the DataSource object.

Format
 
public synchronized void setLogWriter(PrintWriter out) throws SQLException
 

Arguments
PrintWriter out
Log writer

Return value
None.

Exceptions
None.

(2) Package and class names

The names of the package and class for using this interface directly are as follows:

Package name: JP.co.Hitachi.soft.HiRDB.JDBC

Class name: PrdbDataSource