import java.io.*;
    public class TestA implements java.io.Serializable{
    
    
       public static void main(String args[]){
       String a = new String("ALTER");
       whitelist_check_names(a);
       }
    
    public boolean whitelist_check_names(String a) {
    	    boolean flag = true;
            try {
                if ((a.trim()).equals("")) {
                    return false;
                }
                int len = a.length();
                for (int i = 0; i < len; i++) {
                    if ((((int) a.charAt(i)) >= 48 && ((int) a.charAt(i)) <= 57) || (((int) a.charAt(i)) >= 65 && ((int) a.charAt(i)) <= 90) || ((int) a.charAt(i)) == 32 || ((int) a.charAt(i)) == 38 || ((int) a.charAt(i)) == 40 || ((int) a.charAt(i)) == 41 || ((int) a.charAt(i)) == 44 || ((int) a.charAt(i)) == 45 || ((int) a.charAt(i)) == 46 || ((int) a.charAt(i)) == 47 || (((int) a.charAt(i)) >= 97 && ((int) a.charAt(i)) <= 122)) {
                        flag = true;
                    } else {
                        return false;
                    }
                }
                String[] str = {"null","ALTER","DELETE","delete", "SCRIPT", "script"};
                for (int j = 0; j < str.length; j++) {
                    int index = (a.toLowerCase()).indexOf(str[j]);
                    if (index != -1) {
                        return false;
                    }
                }
            } catch (Exception e) {
                String err = e.toString();
                if (err.indexOf("NullPointerException") > 0) {
                    flag = false;
                }
                if (err.indexOf("IOException ") > 0) {
                    flag = false;
                }
                if (err.indexOf("NumberFormatException") > 0) {
                    flag = false;
                }
            }
            return flag;
        }   
          
    }
2
Contributors
2
Replies
37
Views
3 Years
Discussion Span
Last Post by mrabrar09
1

if a method is not static, that means it's an instance method, so you'll have to create an instance of the class and call the method through that instance.

so
whitelist_check_names(a);

becomes:

TestA a = new TestA();
a.whitelist_check_names(a);
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.