To connect to databases using data sources, specify the connection information in the properties of the data source.
Argument | Description |
---|---|
setDataSourceName | Set the data source name used within the application. If more than one data source is created, each should have a unique name. |
setServerName | Specify the host name for the connection destination. |
setPortNumber | Specify the port number for the database server. The default is "26500". |
setDatabaseName | Specify the database name. |
setUser | Specify the username that will connect to the database. If this is omitted, the name used will be that of the user on the operating system that is executing the application. |
setPassword | Specify a password when authentication is required. |
setLoginTimeout | Specify the timeout for connections (in units of seconds). Specify a value between 0 and 9223372036854775. 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.PGPoolingDataSource; ... PGPoolingDataSource source = new PGPoolingDataSource(); source.setDataSourceName("jdbc/ds1"); source.setServerName("sv1"); source.setPortNumber(26500); source.setDatabaseName("mydb"); source.setUser("myuser"); source.setPassword("myuser01"); source.setLoginTimeout(20); source.setSocketTimeout(20); ... Connection con = source.getConnection();