To connect to databases using data sources, specify the connection information in the properties of the data source.
Argument | Description |
|---|---|
setServerName | Specify the host name for the connection destination. The default is "localhost". |
setPortNumber | Specify the port number for the database server. The default is "27500". |
setDatabaseName | Specify the database name. |
setUser | Specify the username of the database. By default, the name used will be that of the user on the operating system that is executing the application. |
setPassword | Specify a password for server authentication. |
setLoginTimeout | Specify the timeout for connections (in units of seconds). Specify a value between 0 and 2147483647. There is no limit set if you set 0 or an invalid value. An error occurs when a connection cannot be established within the specified time. |
setSocketTimeout | Specify the timeout for communication with the server (in units of seconds). Specify a value between 0 and 2147483647. There is no limit set if you set 0 or an invalid value. An error occurs when data is not received from the server within the specified time. |
Example
Code examples for applications
import java.sql.*;
import org.postgresql.ds.PGConnectionPoolDataSource;
...
PGConnectionPoolDataSource source = new PGConnectionPoolDataSource();
source.setServerName("sv1");
source.setPortNumber(27500);
source.setDatabaseName("mydb");
source.setUser("myuser");
source.setPassword("myuser01");
source.setLoginTimeout(20);
source.setSocketTimeout(20);
...
Connection con = source.getConnection();