add to StringBuilder an escaped entity, field for SQLite (encapsulate it in single quote) - Java java.lang

Java examples for java.lang:String Quote

Description

add to StringBuilder an escaped entity, field for SQLite (encapsulate it in single quote)

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        StringBuilder sb = new StringBuilder();
        String entityOrField = "java2s.com";
        System.out.println(appendEscapedEntityOrField(sb, entityOrField));
    }/*from  w  w  w  .  ja va  2  s  .c  om*/

    /**
     * Utility method to add to the sb StringBuilder an escaped entity, field for SQLite (encapsulate it in single quote)
     *
     * @param sb            the StringBuilder
     * @param entityOrField the name of the entity or field
     * @return the quoted entity/field
     */
    public static StringBuilder appendEscapedEntityOrField(
            final StringBuilder sb, final String entityOrField) {
        return sb.append('\'').append(entityOrField).append('\'');
    }
}

Related Tutorials