Class MSql


  • public class MSql
    extends Object
    • Constructor Detail

      • MSql

        public MSql()
    • Method Detail

      • encode

        public static String encode​(String string,
                                    boolean notNull)
        Prepare a string to use it in a sql query. It will also append the quots. A null string will be represented as one space of NULL
        Parameters:
        string -
        notNull - Set to true will return a single space instead of the string NULL
        Returns:
        encoded string
      • escape

        public static String escape​(String in)
        Escape all single quots to double single quots.
        Parameters:
        in -
        Returns:
        escaped string
      • unescape

        public static String unescape​(String in)
        Remove all double single quots.
        Parameters:
        in -
        Returns:
        unescaped string
      • escape

        public static String escape​(String in,
                                    int truncateSize)
        Escape single quots and truncates the string is needed.
        Parameters:
        in -
        truncateSize -
        Returns:
        escaped string
      • executeUpdateQueries

        public static void executeUpdateQueries​(Statement sth,
                                                String sql)
                                         throws SQLException
        Executes a bundle of queries, separated by semicolon.
        Parameters:
        sth -
        sql -
        Throws:
        SQLException
      • quoteSQL

        public static String quoteSQL​(String sql)
        used to prepare SQL string literals by doubling each embedded ' and wrapping in ' at each end. Further quoting is required to use the results in Java String literals. If you use PreparedStatement, then this method is not needed. The ' quoting is automatically handled for you.
        Parameters:
        sql - Raw SQL string literal
        Returns:
        sql String literal enclosed in '
      • toSqlLabel

        public static String toSqlLabel​(String in,
                                        Connection con)
        Removes all non standard characters. Currently do not validate keywords.
        Parameters:
        in - The string to validate
        con - Optional the sql connection to validate keywords. null is possible.
        Returns:
        normalized string
      • column

        public static String column​(String name)
                             throws SQLException
        Validate the name as a column name. If the name contains not allowed characters the method will throw a sql exception. Use this method to deny sql injection for column names.
        Parameters:
        name - The name of the column
        Returns:
        The name. The method can be used in line.
        Throws:
        SQLException