Class OraSQLUtil


  • public class OraSQLUtil
    extends Object
    The OraSQLUtil class is an Oracle SQL utility class.

    The following functionality is available in this class:

    • Data Validation - validates whether data can be stored safely into the database in the specified character set.
    • Data Conversion - converts all characters that cannot be stored in the database in the specified charcter set into Unicode escape forms, such as \[0-9A-Z]{4}, for the UNISTR function
    • Database session synchronization - synchronizes the NLS database session parameters with the Java locale or the Oracle language and territory
    Since:
    10.1.0.2
    • Method Detail

      • isValidIdentifier

        public static boolean isValidIdentifier​(String srcstr,
                                                String dbCharset)
                                         throws UnsupportedEncodingException
        Checks if the string is valid in the database character set.
        Parameters:
        srcstr - a string to be examined
        dbCharset - Oracle database character set name
        Returns:
        true if the data is valid in the database character set, otherwise false
        Throws:
        UnsupportedEncodingException - if the dbCharset parameter is invalid
      • escapeUNISTR

        public static String escapeUNISTR​(String str,
                                          String dbCharset)
                                   throws UnsupportedEncodingException
        Escapes the string into UNISTR form if the character is not supported by the database character set.
        Parameters:
        str - a string to be examined
        dbCharset - Oracle database character set name
        Returns:
        a UNISTR string containing Unicode escaped form if the character is not supported by the character set
        Throws:
        UnsupportedEncodingException - if the dbCharset parameter is invalid
      • synchronizeLocale

        public static boolean synchronizeLocale​(Locale locale,
                                                Connection con)
                                         throws SQLException
        Synchronizes the session NLS parameters with the locale.

        This executes ALTER SESSION SQL commands to set NLS session parameters to synchronize the locale and attributes in this object. The following session parameters are updated:

        • NLS_LANGUAGE
        • NLS_TERRITORY
        Parameters:
        locale - Java locale object
        con - database connection
        Returns:
        true if successful, otherwise false
        Throws:
        SQLException - if a SQL exception occurs
      • synchronizeLocale

        public static boolean synchronizeLocale​(String oralanguage,
                                                String oraterritory,
                                                Connection con)
                                         throws SQLException
        Synchronizes the database session NLS parameters with the Oracle language and territory names.

        This executes ALTER SESSION SQL commands to set NLS session parameters to synchronize the locale and attributes in this object. The following session parameters are updated:

        • NLS_LANGUAGE
        • NLS_TERRITORY
        Parameters:
        oralanguage - Oracle language name
        oraterritory - Oracle territory name
        con - database connection
        Returns:
        true if successful, otherwise false
        Throws:
        SQLException - if a SQL exception occurs