private boolean validateFileLine(String str_Line, String sql_type) {
if (sql_type.equals(INSERT)) {
if (str_Line.toUpperCase().contains("INTO")
&& str_Line.toUpperCase().contains("VALUES"))
return true;
} else if (sql_type.equals(SELECT)) {
if (str_Line.toUpperCase().contains("FROM")
&& str_Line.toUpperCase().contains("WHERE")) {
return true;
}
} else if (sql_type.equals(UPDATE)) {
if (str_Line.toUpperCase().contains("SET")
&& str_Line.toUpperCase().contains("WHERE")) {
return true;
}
} else if (sql_type.equals(DELETE)) {
if (str_Line.toUpperCase().contains("WHERE")) {
return true;
}
}
return false;
}
private String getSQLType(File file) {
if (file.getName().toUpperCase().contains(SELECT)) {
return SELECT;
} else if (file.getName().toUpperCase().contains(UPDATE)) {
return UPDATE;
} else if (file.getName().toUpperCase().contains(DELETE)) {
return DELETE;
} else if (file.getName().toUpperCase().contains(INSERT)) {
return INSERT;
}
return null;
}
public boolean getSqlMode(String args, String fileName) {
if (args == null || ALL.equalsIgnoreCase(args))
return (fileName.startsWith(INSERT) || fileName.startsWith(DELETE)
|| fileName.startsWith(UPDATE) || fileName
.startsWith(SELECT));
if ((SELECT).equalsIgnoreCase(args)) {
return (fileName.startsWith(SELECT));
} else if ((UPDATE).equalsIgnoreCase(args)) {
return (fileName.startsWith(UPDATE));
} else if ((INSERT).equalsIgnoreCase(args)) {
return (fileName.startsWith(INSERT));
} else if ((DELETE).equalsIgnoreCase(args)) {
return (fileName.startsWith(DELETE));
}
return false;
}
}
如果需要得到a.log中的sql语句,
就可以这样调用java程序 java LogToSqlMain a.log INSET
如果想得到所有的sql语句 java LogToSqlMain a.log ALL