Created
February 12, 2010 21:08
-
-
Save arockwell/302984 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package template; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| public class InsertStatementGenerator implements DelimitedStringParser { | |
| private int lineCounter = 0; | |
| private String tableName = ""; | |
| private List<String> columns = new ArrayList<String>(); | |
| public String doParseLine(String rawLine) { | |
| String result; | |
| String[] tempCols = rawLine.split(","); | |
| if (lineCounter == 0) { | |
| tableName = tempCols[0]; | |
| for (int i = 1; i < tempCols.length; i++) { | |
| columns.add(tempCols[i]); | |
| } | |
| result = ""; | |
| } else { | |
| result = "insert into " + tableName + "("; | |
| for (int i = 0; i < columns.size(); i++) { | |
| if (i != columns.size() - 1) { | |
| result += columns.get(i) + ","; | |
| } else { | |
| result += columns.get(i) + ")"; | |
| } | |
| } | |
| result += "VALUES ("; | |
| for (int i = 0; i < tempCols.length; i++) { | |
| if (i != tempCols.length - 1) { | |
| result += tempCols[i] + ","; | |
| } else { | |
| result += tempCols[i] + ")"; | |
| } | |
| } | |
| } | |
| lineCounter++; | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment