As of now i just want to check whether the order of the clauses - select, from, where, order by. are correct in a query. I tried this:
String pattern1 = "select";
String pattern2 = "from";
String pattern3 = "(where\\s*(.*?)|order by\\s*(.*?)|where\\s*(.*?)order by\\s*(.*?))";
String pattern4 = "(;|$)";
Pattern p = Pattern.compile(pattern1 + "(.*?)" + pattern2 + "(.*?)" + pattern3 + pattern4);
But still this matches an incorrect query like this:
select * from student order by marks where id<8;
I need to do it manually without using any external libraries.