Top
Symfoware Server V12.0.0 Application Development Guide
FUJITSU Software

2.3.1 Using the DriverManager Class

To connect to the database using the DriverManager class, first load the JDBC driver, then specify the connection string as a URL in the API of the DriverManager class.

Load the JDBC driver

Specify org.postgresql.Driver.

Connection string

URL connection is performed as follows:

jdbc:postgresql://host:port/database?user=user&password=password1&loginTimeout=loginTimeout&socketTimeout=socketTimeout

Argument

Description

host

Specify the host name for the connection destination.

port

Specify the port number for the database server.

The default is "26500".

database

Specify the database name.

user

Specify the username that will connect with the database.

If this is omitted, the username logged into the operating system that is executing the application will be used.

password

Specify a password when authentication is required.

loginTimeout

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.

socketTimeout

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.*;
...
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://sv1:26500/mydb?user=myuser&password=myuser01&loginTimeout=20&socketTimeout=20";
Connection con = DriverManager.getConnection(url);