小弟遇到一难题,代码如下:
String[] DML_INSERT = { "insert", "into", "(", ")", "values", "(", ")"
private void InsertDone(Map map){
Map infoTable = new HashMap();
// 添加表名
infoTable.put("name", map.get(DML_INSERT[1]));
// 获得表中的字段
String[] column = (String[]) map.get(DML_INSERT[2]);
// 添加字段
for (int i = 0; i < column.length; i++) {
infoTable.put(column[i], "");
}
//获得要插入的值
String[] value = (String[]) map.get(DML_INSERT[5]);
//添加值
for(int j=0;j< value.length;j++){
value[j] = "'"+value[j]+"'";
infoTable.put(value[j],"");
}
// 保存创建结构
Container.serial(infoTable, (String) map.get(DML_INSERT[1]));
}
private Map InsertPrepare(String formatSrcipt){
Map MapInfo = new HashMap();
String insertType = StringUtils.substringBefore(formatSrcipt, " ");
if (DML_INSERT[1].equals(insertType.trim())) {// 检查类型是否是 TABLE
String tableName = StringUtils.substringBetween(formatSrcipt,
DML_INSERT[1], DML_INSERT[2]);
if (tableName == null || tableName.trim().length() == 0) {
System.err.println("无效DML脚本,缺少表名");
return null;
}
MapInfo.put(DML_INSERT[1], tableName.trim());
String column = StringUtils.substringBetween(formatSrcipt,DML_INSERT[2], DML_INSERT[3]);
if (column == null || column.trim().length() == 0) {
System.err.println("无效DML脚本,缺少字段");
return null;
}
String[] columnArr = column.split(",");
MapInfo.put(DML_INSERT[2], columnArr);
String values = StringUtils.substringBetween(formatSrcipt,DML_INSERT[5],DML_INSERT[6]);
String[] columnArr1 = values.split(",");
MapInfo.put(DML_INSERT[5],columnArr1);
}else {
System.err.println("无效脚本,缺少关键字");
return null;
}
return MapInfo;
}
public static void main(String[] args) {
DMLSyntaxParserImpl dpl = new DMLSyntaxParserImpl();
dpl.opedo("insert into table5 (column1,column2) values (value1,value2)");
Map map = (Map) Container.fetchData("table5");
for (Iterator itr = map.k**Set().iterator(); itr.hasNext();) {
Object k** = itr.next();
System.out.println(k** + ":" + map.get(k**));
}
希望得到的结果是能将DML语句里的column1,column2,value1,value2提取出来,可得到的结果是column1,column2,'column1',column2'
小弟初学java,还希望哪位高人能帮我指点指点