Fujitsu Logo
ENQUIRE

    Knowledge articles - Application development

    icon-kb-article-appdev-color-simple

    How do I connect to a database from my application using JDBC driver?KB7001

    You can connect to a database via an application using the DriverManager, PGConnectionPoolDataSource, and PGXADataSource JDBC driver classes.

    The following is an example of using the PGConnectionPoolDataSource class to connect to a database:

    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 ();

    For details, refer to FUJITSU Enterprise Postgres Application Development Guide > Chapter 2 - JDBC driver > 2.3 - Connecting to the database.

    Applicable to

    Product: FUJITSU Enterprise Postgres SE, FUJITSU Enterprise Postgres AE, PostgreSQL

    Architecture: X86, S390x

    Operating System: Windows, Linux

    Versions: from 9.5

    How do I cancel a query that has been running for a long time, or break a connection that has been waiting for a long time?KB7002

    The query can be cancelled by using the pg_cancel_backend function, and connections can be forcibly broken using either the pg_terminate_backend function or pgAdmin.

    In the pg_cancel_backend and pg_terminate_backend functions, the process ID specifies the query to cancel or connection to break. The process ID can be found in the pg_stat_activity view or with the OS ps command.

    Applicable to

    Product: FUJITSU Enterprise Postgres SE, FUJITSU Enterprise Postgres AE, PostgreSQL

    Architecture: X86, S390x

    Operating System: Windows, Linux

    Versions: from 9.5

    An application using JDBC driver shows the error message The new connection was automatically closed because the same PooledConnection was opened or PooledConnection is already closed.KB7003

    This may have happened because the application was trying to work on a Connection object that had already been closed.

    Review your application's handling of Connection objects as follows:

    • Are you executing a method on a Connection object that has already been closed?
    • Did you execute the getConnection method multiple times on the same instance of the PGPooledConnection or PGXAConnection class, and not on the Connection object returned by the last execution?
    • When you execute the getConnection method on a PGPooledConnection or PGXAConnection class, the relationship between these classes and the getConnection method to be executed is one-to-one. If the getConnection method is executed more than once using an instance of the same class, the previously created Connection object is closed.

    Applicable to

    Product: FUJITSU Enterprise Postgres SE, FUJITSU Enterprise Postgres AE, PostgreSQL

    Architecture: X86, S390x

    Operating System: Windows, Linux

    Versions: from 9.5

    A System.OutOfMemoryException exception was raised when running a .NET application.KB7004

    Possible causes include the following:

    • ExecuteReader() is running on a table with binary column data types or other large data structures
    • The connection string to the database specifies PreloadReader = true
    The above execution or specification holds the data for the entire result set in memory. This may have consumed a large amount of memory and run out of memory.

    Resolution

    Consider making the following changes:

    • Change ExecuteReader() to ExecuteReader(CommandBehavior.SequentialAccess)
    • Change PreloadReader = True to PreloadReader = False
    For more information, refer to:

    Applicable to

    Product: FUJITSU Enterprise Postgres SE, FUJITSU Enterprise Postgres AE, PostgreSQL

    Architecture: X86, S390x

    Operating System: Windows, Linux

    Versions: from 9.5

    When I connect to a database from a .NET application, the error message ERROR: 80027: Timeout while getting a connection from pool is displayed.KB7005

    It is possible that the application is not disconnecting from the database, leaving unnecessary connections and exceeding the maximum number of connection pools.

    If a connection is requested beyond the maximum number of connection pools, it will wait until an available connection is found. If no available connection is found and the connection timeout period is exceeded, the connection request will timeout.

    Resolution

    Check the connection that has been waiting for a long time, and close any unnecessary connection.

    Also, ensure that the application is disconnecting from the database. If it already is, please review the maximum number of connection pools specified in the connection string - this is specified by the Maximum Pool Size keyword, and the default is 100.

    An application using JDBC driver shows the error message 55000: PostgreSQL JDBC Driver ERROR: prepared transactions are disabled and 42704: PostgreSQL JDBC Driver ERROR: prepared transaction with identifier "xxx" does not exist.KB7006

    This happened because PREPARE TRANSACTION was performed with the max_prepared_transactions parameter set to 0 in postgresql.conf.

    Resolution

    Set max_prepared_transactions to at least 1 in postgresql.conf.

    Applicable to

    Product: FUJITSU Enterprise Postgres SE, FUJITSU Enterprise Postgres AE, PostgreSQL

    Architecture: X86, S390x

    Operating System: Windows, Linux

    Versions: from 9.5

    Can I install ODBC drivers separately on the client side?KB7007

    ODBC drivers cannot be installed separately - they are installed with the FUJITSU Enterprise Postgres client.

    Applicable to

    Product: FUJITSU Enterprise Postgres SE, FUJITSU Enterprise Postgres AE, FUJITSU Enterprise Postgres for Kubernetes, PostgreSQL

    Architecture: X86, S390x

    Operating System: Windows, Linux

    Versions: from 9.5

    Read our latest blogs

    Read our most recent articles regarding all aspects of PostgreSQL and FUJITSU Enterprise Postgres.