Java SQL Time Format formatExceptionForToolsWithLimitedCharacterSet(String exceptionLabel)

Here you can find the source of formatExceptionForToolsWithLimitedCharacterSet(String exceptionLabel)

Description

Some tools don't allow for special characters in their monitoring labels.

License

Apache License

Parameter

Parameter Description
exceptionLabel a parameter

Declaration

public static String formatExceptionForToolsWithLimitedCharacterSet(String exceptionLabel) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from w ww.j  a v  a 2  s  .  c o m
     * Some tools don't allow for special characters in their monitoring labels. For example
     * StatsD doesn't allow '.=' and JavaSimon doesn't allow ' ='.  The following method strips
     * these characters out of the exception string for SQL so they will work in these api's.  
     * This is done for sql exceptions of the format:   
     *  java.sql.SQLException,ErrorCode=400,SQLState=Login failure
     * 
     * Note at the time of this writing JavaSimon uses this regular expression for labels: '[-_\[\]A-Za-z0-9.,@$%)(<>]+'
     * 
     * @param exceptionLabel
     * @return 
     */
    public static String formatExceptionForToolsWithLimitedCharacterSet(String exceptionLabel) {
        if (exceptionLabel == null) {
            return null;
        }

        return exceptionLabel.replace(",ErrorCode=", ".ErrorCode ").replace(",SQLState=", "-SQLState ");
    }
}

Related

  1. formatDate(String Format)
  2. formatDateWithSlashes(java.sql.Date date)
  3. formatDateYM(Date date, String datePtn)
  4. formatDateYMD(String str, String datePtn)
  5. formatDefaultValue(Object o)
  6. formatTime(Date date)
  7. formatTime(final Time time)
  8. formatTime(Time time, String format)
  9. formatTimeToFloat(Time inputTime)