DataBridge Documentation 2.0.17
A Java library for managing database connections and transactions
Loading...
Searching...
No Matches
io.github.kdesp73.databridge.connections.PostgresConnection Class Reference
Inheritance diagram for io.github.kdesp73.databridge.connections.PostgresConnection:
io.github.kdesp73.databridge.connections.DatabaseConnection AutoCloseable

Public Member Functions

ResultSet callFunction (String functionName, Object... params) throws SQLException
 
Object callFunctionValue (String functionName, int returnType, Object... params) throws SQLException
 
void callProcedure (String procedureName, Object... params) throws SQLException
 
void close () throws SQLException
 
void connect (String url, String username, String password) throws SQLException
 
boolean execute (String query) throws SQLException
 
ResultSet executeQuery (String query) throws SQLException
 
int executeUpdate (String query) throws SQLException
 
Connection get ()
 
- Public Member Functions inherited from io.github.kdesp73.databridge.connections.DatabaseConnection

Detailed Description

The PostgresConnection class implements the DatabaseConnection interface for connecting to and interacting with a PostgreSQL database.

This class provides methods to establish a connection, execute SQL queries (SELECT, UPDATE), call PostgreSQL functions and procedures, and close the connection. It also supports calling functions that return values or tables and handles retries for failed operations using the Again helper.

This class also logs errors related to database operations using the SQLogger.

Author
KDesp73

Member Function Documentation

◆ get()

Connection io.github.kdesp73.databridge.connections.PostgresConnection.get ( )

Returns the underlying Connection object for the PostgreSQL database.

Returns
the Connection instance for the database connection.

Implements io.github.kdesp73.databridge.connections.DatabaseConnection.

◆ connect()

void io.github.kdesp73.databridge.connections.PostgresConnection.connect ( String url,
String username,
String password ) throws SQLException

Establishes a connection to the PostgreSQL database.

The connection URL must begin with jdbc:postgresql://, followed by the host, port, and database name. If the URL does not start with this prefix, it will be automatically added.

Parameters
urlthe database URL in the format jdbc:postgresql://host:port/database.
usernamethe username for database access.
passwordthe password for database access.
Exceptions
SQLExceptionif the connection to the database fails.

Implements io.github.kdesp73.databridge.connections.DatabaseConnection.

◆ executeUpdate()

int io.github.kdesp73.databridge.connections.PostgresConnection.executeUpdate ( String query) throws SQLException

Executes an UPDATE SQL query (INSERT, UPDATE, DELETE) on the PostgreSQL database.

This method attempts the query execution with retries in case of failure, using the Again helper.

Parameters
querythe SQL query string to execute.
Returns
the number of rows affected by the query.
Exceptions
SQLExceptionif a database access error occurs or if the query is invalid.

Implements io.github.kdesp73.databridge.connections.DatabaseConnection.

◆ executeQuery()

ResultSet io.github.kdesp73.databridge.connections.PostgresConnection.executeQuery ( String query) throws SQLException

Executes a SELECT SQL query and returns the result as a ResultSet.

This method attempts the query execution with retries in case of failure, using the Again helper.

Parameters
querythe SQL SELECT query string to execute.
Returns
a ResultSet containing the result of the query.
Exceptions
SQLExceptionif a database access error occurs or if the query is invalid.

Implements io.github.kdesp73.databridge.connections.DatabaseConnection.

◆ execute()

boolean io.github.kdesp73.databridge.connections.PostgresConnection.execute ( String query) throws SQLException

Executes a DDL SQL query (e.g., CREATE, ALTER, DROP) on the PostgreSQL database.

This method attempts the query execution with retries in case of failure, using the Again helper.

Parameters
querythe SQL DDL query string to execute.
Returns
true if the query executed successfully, false otherwise.
Exceptions
SQLExceptionif a database access error occurs or if the query is invalid.

Implements io.github.kdesp73.databridge.connections.DatabaseConnection.

◆ close()

void io.github.kdesp73.databridge.connections.PostgresConnection.close ( ) throws SQLException

Closes the database connection, releasing any resources.

Exceptions
SQLExceptionif an error occurs while closing the connection.

Implements io.github.kdesp73.databridge.connections.DatabaseConnection.

◆ callFunction()

ResultSet io.github.kdesp73.databridge.connections.PostgresConnection.callFunction ( String functionName,
Object... params ) throws SQLException

Calls a PostgreSQL function that returns a table of records.

This method prepares and executes a SQL query to call the specified PostgreSQL function, returning the result as a ResultSet.

Parameters
functionNamethe name of the PostgreSQL function to call.
paramsthe parameters to pass to the function.
Returns
a ResultSet containing the results of the function call. The caller is responsible for closing the ResultSet.
Exceptions
SQLExceptionif an error occurs during the function call.

◆ callFunctionValue()

Object io.github.kdesp73.databridge.connections.PostgresConnection.callFunctionValue ( String functionName,
int returnType,
Object... params ) throws SQLException

Calls a PostgreSQL function that returns a single value.

This method prepares and executes a SQL call to the specified PostgreSQL function, returning the value of the result.

Parameters
functionNamethe name of the PostgreSQL function to call.
returnTypethe JDBC return type of the function result.
paramsthe parameters to pass to the function.
Returns
the result of the function call.
Exceptions
SQLExceptionif an error occurs during the function call.

◆ callProcedure()

void io.github.kdesp73.databridge.connections.PostgresConnection.callProcedure ( String procedureName,
Object... params ) throws SQLException

Calls a PostgreSQL stored procedure.

This method prepares and executes a SQL call to the specified stored procedure.

Parameters
procedureNamethe name of the PostgreSQL procedure to call.
paramsthe parameters to pass to the procedure.
Exceptions
SQLExceptionif an error occurs during the procedure call.

The documentation for this class was generated from the following file: