Java SQL Date Format formatBytableCols(Object[] obj, String[] tableCols)

Here you can find the source of formatBytableCols(Object[] obj, String[] tableCols)

Description

format Bytable Cols

License

Open Source License

Declaration

public static String formatBytableCols(Object[] obj, String[] tableCols) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {

    public static String formatBytableCols(Object[] obj, String[] tableCols) {
        StringBuffer result = new StringBuffer();
        result.append("{");
        if (obj != null && obj.length > 0) {
            for (int i = 0; i < obj.length; i++) {
                try {
                    result.append(tableCols[i]);
                    result.append(":'");
                    if (obj[i] instanceof String) {
                        String s = null;
                        if (obj[i].toString() != null) {
                            s = obj[i].toString().replace("\"", "\\\"").replace("'", "\\'").replace("\n", "<br/>")
                                    .replace("\b", "\\b").replace("\f", "\\f").replace("\r", "").replace("\t", "");
                        }//from w ww .ja  v  a 2 s . com
                        result.append(s);
                    } else if (obj[i] instanceof Integer) {
                        result.append((Integer) obj[i]);
                    } else if (obj[i] instanceof Long) {
                        result.append((Long) obj[i]);
                    } else if (obj[i] instanceof Double) {
                        result.append((Double) obj[i]);
                    } else if (obj[i] instanceof java.sql.Date) {
                        result.append((java.sql.Date) obj[i]);
                    } else if (obj[i] instanceof Float) {
                        result.append((Float) obj[i]);
                    }
                    result.append("'");
                    if (i < obj.length - 1) {
                        result.append(",");
                    }

                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (SecurityException e) {
                    e.printStackTrace();
                }

            }
        }
        result.append("}");
        System.out.println(result.toString());
        return result.toString();
    }

    public static String formatBytableCols(List<Object[]> list, String[] tableCols) {
        StringBuffer result = new StringBuffer();
        result.append("[");
        if (!list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                Object[] obj = (Object[]) list.get(i);
                result.append(formatBytableCols(obj, tableCols));
                if (i < list.size() - 1)
                    result.append(",");
            }

        }
        result.append("]");
        return result.toString();
    }
}

Related

  1. dateFormat(String sdate, String format)
  2. dateFormatJson(Date date)
  3. dateFromLong(Long longObject)
  4. formataData(Date data)
  5. formatAsText(ResultSet result_set, PrintWriter out)
  6. formatDate(java.util.Date uDate)
  7. formatDate(Object obj)
  8. formatDate(String date)
  9. formatDateTd(Object obj)