我正在尝试使用从视图(JSP)到控制器的最终用户的选定字段进行查询,但我不知道如何。
例如,我有这个参数来自视图(JSP)
IDUSER,>,2,OR,USERNAME,=,'KURT'
所以,我想要这样的东西,
SELECT IDUSER, USERNAME FROM TABLE_NAME WHERE IDUSER > 2 OR USERNAME = 'KURT'
但我有下一个结果
SELECT null FROM TABLE_NAME WHERE IDUSER > 2 OR USERNAME = 'KURT'
我正在用StringTokenizer
类解析字符串,其中查询是:String query = request.getParameter("data");
而数据是IDUSER,>,2,OR,USERNAME,=,'KURT'
。
StringTokenizer field = new StringTokenizer(query, ",");
nFields = field.countTokens();
System.out.println("nFields: " + nFields);
String[] fields = new String[nFields];
for(int i = 0; i < fields.length; i++) {
while(field.hasMoreTokens()) {
fields[i] = field.nextToken();
}
System.out.println("fields[i]: " + fields[i]);
myQuery = "SELECT " + fields[i] + " FROM "+tableName+ " WHERE ";
System.out.println("myQuery 1: " + myQuery);
}
StringTokenizer token= new StringTokenizer(query, "|,");
while(token.hasMoreTokens()) {
myQuery = myQuery + token.nextToken() + " ";
}
System.out.println("QUERY RESOLVED: " + myQuery);
请帮我