DataSource interface

A factory for connections to the physical data source that this DataSource object represents. A replacement for the DriverManager facility, a DataSource object is the preferred means of getting a connection.

An instance of a DataSource object can be used in a stand alone program to create Connection objects. In the following example, an instance of DB2eDataSource is used to create a Connection to a DB2 Everyplace database with url "jdbc:db2e:myDataSource":

com.ibm.db2e.jdbc.DB2eDataSource ds = new com.ibm.db2e.jdbc.DB2eDataSource();
    ds.setUrl("jdbc:db2e:myDataSource");
    Connection con = ds.getConnection();

javax.sql package

public interface DataSource

Tabulka 110 and Tabulka 111 list the properties for the DataSource interface that are supported by DB2 Everyplace. The properties can be accessed using "getter" and "setter" methods. (DataSource properties follow the convention specified for properties of JavaBeans(TM) components in the JavaBeans 1.01 Specification.)

Tabulka 110. Standard DataSource properties supported by DB2 Everyplace

Property Name Type Description
description String description of this data source
password String database password
user String user's account name

Tabulka 111 lists the supported properties for the DataSource interface that are specific to DB2 Everyplace.

Tabulka 111. DB2 Everyplace-specific properties for the DataSource interface

Property Name Type Description
encoding String character encoding
URL String data source

Tabulka 112 lists the methods in the DataSource interface that are supported by DB2 Everyplace.

Tabulka 112. DataSource interface methods

Method return value type Method
Connection getConnection() Attempts to establish a connection with the data source that this DataSource object represents.
Connection getConnection (java.lang.String username, java.lang.String password) Attempts to establish a connection with the data source that this DataSource object represents.
int getLoginTimeout() Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
java.io.PrintWriter getLogWriter() Retrieves the log writer for this DataSource object.
void setLoginTimeout(int seconds) Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
void setLogWriter(java.io.PrintWriter out) Sets the log writer for this DataSource object to the given java.io.PrintWriter object.

Související úlohy

Související odkazy