here where am doing mistake and program is showing error non static method cannot be refferenced to static context
Non-static method
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;
}
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.