DbUtil

Framework Components [com.onepg.db]

← Back to Class List

Class Information

Package: com.onepg.db

Class Name: DbUtil

Description

Database utility class.

Method List

getConn

public Connection getConn()
Retrieves the default database connection.
  • Declare in a try clause (try-with-resources statement).

Return Value

Connection - the database connection

getConn

public Connection getConn(String traceCode)
Retrieves the default database connection.
  • Declare in a try clause (try-with-resources statement).

Parameters

Name Type Description
traceCode String trace code

Return Value

Connection - the database connection

getConnByConfigName

public Connection getConnByConfigName(String connName)
Retrieves a database connection with the specified connection name.
  • Declare in a try clause (try-with-resources statement).

Parameters

Name Type Description
connName String database connection name in the configuration file (the part before .dbcon.url)

Return Value

Connection - the database connection

getConnByConfigName

public Connection getConnByConfigName(String connName, String traceCode)
Retrieves a database connection with the specified connection name.
  • Declare in a try clause (try-with-resources statement).

Parameters

Name Type Description
connName String database connection name in the configuration file (the part before .dbcon.url)
traceCode String trace code

Return Value

Connection - the database connection

getConnPooled

public Connection getConnPooled()
Retrieves the default pooled database connection.
  • Retrieves a pooled database connection.
  • Declare in a try clause (try-with-resources statement).

Return Value

Connection - the database connection

getConnPooled

public Connection getConnPooled(String traceCode)
Retrieves the default pooled database connection.
  • Retrieves a pooled database connection.
  • Declare in a try clause (try-with-resources statement).

Parameters

Name Type Description
traceCode String trace code

Return Value

Connection - the database connection

getConnPooledByConfigName

public Connection getConnPooledByConfigName(String connName)
Retrieves a pooled database connection with the specified connection name.
  • Retrieves a pooled database connection.
  • Declare in a try clause (try-with-resources statement).

Parameters

Name Type Description
connName String database connection name in the configuration file (the part before .dbcon.url)

Return Value

Connection - the database connection

getConnPooledByConfigName

public Connection getConnPooledByConfigName(String connName, String traceCode)
Retrieves a pooled database connection with the specified connection name.
  • Retrieves a pooled database connection.
  • Declare in a try clause (try-with-resources statement).

Parameters

Name Type Description
connName String database connection name in the configuration file (the part before .dbcon.url)
traceCode String trace code

Return Value

Connection - the database connection

getConnByUrl

public Connection getConnByUrl(String url, String user, String pass, String traceCode)
Retrieves a database connection with the specified JDBC URL.
  • Declare in a try clause (try-with-resources statement).

Parameters

Name Type Description
url String JDBC connection URL
user String database user
pass String database password
traceCode String

Return Value

Connection - the database connection

closePooledConn

public void closePooledConn()
Closes pooled database connections.
  • Disconnects all pooled database connections.
  • Also disconnects busy connections.

getConnNames

public String[] getConnNames()
Retrieves database connection configuration names.

Return Value

String[] - the array of connection names with URLs configured (includes the default connection name)

isExistsTable

public boolean isExistsTable(Connection conn, String tableName)
Checks if the table exists.

Parameters

Name Type Description
conn Connection database connection
tableName String table name

Return Value

boolean - true if the table exists

getPrimaryKeys

public String[] getPrimaryKeys(Connection conn, String tableName)
Retrieves the primary key column names.
  • Retrieves primary key column names of the table from JDBC metadata.
  • Returns an empty array for tables without a primary key.
  • Converts column physical names to lowercase letters. (Key rule of AbstractIoTypeMap)

Parameters

Name Type Description
conn Connection database connection
tableName String table name

Return Value

String[] - the primary key column name array (lowercase, in KEY_SEQ order)