从java中获取SQL查询的条件

时间:2017-11-14 09:40:48

标签: sql

如何从SQL查询获得准确的条件,如下所示:

select * from users where name = "ned stark" order by id ;
select * from users where name = "rob stark" group by id ;

我想得到' name = "ned stark"'和' name = "rob stark"&#39 ;; 有没有办法做到这一点?

2 个答案:

答案 0 :(得分:1)

您可以使用简单的子字符串来解决您的问题:

String aa = "select * from test where a='aa' and b='bb' order by aa";
int startIndext = aa.indexOf("where") + 5;
int endIndex = aa.indexOf("group");
if(endIndex<0) endIndex = aa.indexOf("order");
if(endIndex<0) endIndex = aa.length();
String whereCondition = aa.substring(startIndext, endIndex);
System.out.println("whereCondition: " + whereCondition);

答案 1 :(得分:0)

试试这个:

select * from users where name = "ned stark" or name = "rob stark" order by id ;