Here you can find the source of splitSQLColumns(String sql)
public static String[] splitSQLColumns(String sql)
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.util.ArrayList; import java.util.List; public class Main { /**//from w w w.j a va2s. c o m * split SQL columns like that : * from : * id, name, CONCAT(name,UPPER(address)), CONCAT(age,name) * to * [id] [name] [CONCAT(name,UPPER(address))] [CONCAT(age,name)] */ public static String[] splitSQLColumns(String sql) { List<String> result = new ArrayList<String>(); int blockCount = 0; int start = 0; for (int i = 0; i < sql.length(); i++) { char c = sql.charAt(i); if (c == '(') { blockCount++; } else if (c == ')') { blockCount--; } if ((c == ',' && (blockCount < 1))) { result.add(sql.substring(start, i)); start = i + 1; } if (i == (sql.length() - 1)) { result.add(sql.substring(start)); } } return result.toArray(new String[0]); } }