public static boolean restrictQueryExecution ( String sql ) { String [ ] restrictions = { "delete" , "truncate" , "update" , "drop" , "alter" } ; if ( sql != null ) { sql = sql . toLowerCase ( ) ; for ( String restriction : restrictions ) { if ( sql . startsWith ( restriction ) ) { return true ; } String regex = "\\s+" + restriction + "\\s+" ; Pattern pattern = Pattern . compile ( regex ) ; Matcher matcher = pattern . matcher ( sql ) ; if ( matcher . find ( ) ) { return true ; } } } return false ; }
Restrict a query execution . Do not allow for database modifications .