Class JKDataAccessUtil

java.lang.Object
com.jk.data.util.JKDataAccessUtil

public class JKDataAccessUtil extends Object
This class provides utility methods for working with data access operations.

It includes methods for formatting SQL statements, handling binary data from ResultSets, and more.

Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Details

    • JKDataAccessUtil

      public JKDataAccessUtil()
  • Method Details

    • formatStatement

      public static String formatStatement(String statement)
      This method formats a SQL statement by adding indentation for readability.
      Parameters:
      statement - Specifies the SQL statement to format.
      Returns:
      the formatted SQL statement.
    • formatStatementWithParam

      public static String formatStatementWithParam(String statement, Object... params)
      This method formats a SQL statement with its parameters.
      Parameters:
      statement - Specifies the SQL statement to format.
      params - Specifies the parameters associated with the statement.
      Returns:
      the formatted SQL statement with parameters.
    • getBinaryStream

      public static byte[] getBinaryStream(ResultSet rs, String name) throws SQLException
      This method retrieves binary data from a ResultSet using the specified column name.
      Parameters:
      rs - Specifies the ResultSet containing the binary data.
      name - Specifies the name of the column.
      Returns:
      the binary data as a byte array.
      Throws:
      SQLException - if a SQL error occurs while retrieving the data.
    • getBlobColumn

      public static byte[] getBlobColumn(ResultSet rs, String columnName) throws SQLException
      This method retrieves binary data from a ResultSet as a Blob using the specified column name.
      Parameters:
      rs - Specifies the ResultSet containing the binary data as a Blob.
      columnName - Specifies the name of the column.
      Returns:
      the binary data as a byte array.
      Throws:
      SQLException - if a SQL error occurs while retrieving the data.
    • getJdbcDrivers

      public static Properties getJdbcDrivers()
      This method retrieves JDBC driver properties from a properties file.
      Returns:
      the JDBC driver properties as a Properties object.
    • ping

      public static void ping(String driver, String url, String user, String password)
      This method pings a database to check its availability.
      Parameters:
      driver - Specifies the JDBC driver class name.
      url - Specifies the database URL.
      user - Specifies the database user.
      password - Specifies the database password.
    • fetchStruct

      public static List fetchStruct(Struct s)
      This method fetches the elements of a Struct object as a list.
      Parameters:
      s - Specifies the Struct object to fetch elements from.
      Returns:
      a list of elements from the Struct.
    • fetchValue

      public static Object fetchValue(Object a)
      This method fetches a value from an object.
      Parameters:
      a - Specifies the object to fetch a value from.
      Returns:
      the fetched value.
      See Also:
    • fetchArray

      public static List fetchArray(Array array)
      This method fetches elements of an Array as a list.
      Parameters:
      array - Specifies the Array object to fetch elements from.
      Returns:
      the list of elements from the Array.