Class Util

java.lang.Object
com.mysql.jdbc.Util

public class Util extends Object
Various utility methods for the driver.
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • isJdbc4

      public static boolean isJdbc4()
    • isJdbc42

      public static boolean isJdbc42()
    • getJVMVersion

      public static int getJVMVersion()
    • jvmMeetsMinimum

      public static boolean jvmMeetsMinimum(int version, int updateNumber)
    • getJVMUpdateNumber

      public static int getJVMUpdateNumber()
    • isColdFusion

      public static boolean isColdFusion()
    • isCommunityEdition

      public static boolean isCommunityEdition(String serverVersion)
      Checks whether the given server version string is a MySQL Community edition
    • isEnterpriseEdition

      public static boolean isEnterpriseEdition(String serverVersion)
      Checks whether the given server version string is a MySQL Enterprise edition
    • newCrypt

      public static String newCrypt(String password, String seed, String encoding)
    • hashPre41Password

      public static long[] hashPre41Password(String password, String encoding)
    • hashPre41Password

      public static long[] hashPre41Password(String password)
    • newHash

      static long[] newHash(byte[] password)
    • oldCrypt

      public static String oldCrypt(String password, String seed)
    • oldHash

      static long oldHash(String password)
    • scramble

      public static String scramble(String message, String password)
      Parameters:
      message -
      password -
    • stackTraceToString

      public static String stackTraceToString(Throwable ex)
      Converts a nested exception into a nicer message
      Parameters:
      ex - the exception to expand into a message.
      Returns:
      a message containing the exception, the message (if any), and a stacktrace.
    • getInstance

      public static Object getInstance(String className, Class<?>[] argTypes, Object[] args, ExceptionInterceptor exceptionInterceptor) throws SQLException
      Throws:
      SQLException
    • handleNewInstance

      public static final Object handleNewInstance(Constructor<?> ctor, Object[] args, ExceptionInterceptor exceptionInterceptor) throws SQLException
      Handles constructing new instance with the given constructor and wrapping (or not, as required) the exceptions that could possibly be generated
      Throws:
      SQLException
    • interfaceExists

      public static boolean interfaceExists(String hostname)
      Does a network interface exist locally with the given hostname?
      Parameters:
      hostname - the hostname (or IP address in string form) to check
      Returns:
      true if it exists, false if no, or unable to determine due to VM version support of java.net.NetworkInterface
    • calculateDifferences

      public static Map<Object,Object> calculateDifferences(Map<?,?> map1, Map<?,?> map2)
    • loadExtensions

      public static List<Extension> loadExtensions(Connection conn, Properties props, String extensionClassNames, String errorMessageKey, ExceptionInterceptor exceptionInterceptor) throws SQLException
      Returns initialized instances of classes listed in extensionClassNames. There is no need to call Extension.init() method after that if you don't change connection or properties.
      Parameters:
      conn -
      props -
      extensionClassNames -
      errorMessageKey -
      exceptionInterceptor -
      Throws:
      SQLException
    • isJdbcInterface

      public static boolean isJdbcInterface(Class<?> clazz)
      Recursively checks for interfaces on the given class to determine if it implements a java.sql, javax.sql or com.mysql.jdbc interface.
      Parameters:
      clazz - The class to investigate.
    • isJdbcPackage

      public static boolean isJdbcPackage(String packageName)
      Check if the package name is a known JDBC package.
      Parameters:
      packageName - The package name to check.
    • getImplementedInterfaces

      public static Class<?>[] getImplementedInterfaces(Class<?> clazz)
      Retrieves a list with all interfaces implemented by the given class. If possible gets this information from a cache instead of navigating through the object hierarchy. Results are stored in a cache for future reference.
      Parameters:
      clazz - The class from which the interface list will be retrieved.
      Returns:
      An array with all the interfaces for the given class.
    • secondsSinceMillis

      public static long secondsSinceMillis(long timeInMillis)
      Computes the number of seconds elapsed since the given time in milliseconds.
      Parameters:
      timeInMillis - The past instant in milliseconds.
      Returns:
      The number of seconds, truncated, elapsed since timeInMillis.
    • truncateAndConvertToInt

      public static int truncateAndConvertToInt(long longValue)
      Converts long to int, truncating to maximum/minimum value if needed.
      Parameters:
      longValue -
      Returns:
    • truncateAndConvertToInt

      public static int[] truncateAndConvertToInt(long[] longArray)
      Converts long[] to int[], truncating to maximum/minimum value if needed.
      Parameters:
      longArray -
      Returns:
    • getPackageName

      public static String getPackageName(Class<?> clazz)
      Returns the package name of the given class. Using clazz.getPackage().getName() is not an alternative because under some class loaders the method getPackage() just returns null.
      Parameters:
      clazz - the Class from which to get the package name
      Returns:
      the package name