Today, I came out with a question and almost stumped myself ... The
question is this:
There are three sql statements that are known, Xiao Ming accidentally wrote a piece, you help him split it. The sql statement is:"select * from books where bid = 1 select * from cate where name = ‘java’ select title from books where id =2002 "
Here is the implementation code:
public static void testUpS() {
String sql = "select * from books" + "where bid = 1 select * from cate"
+ " where name = 'java' select title"
+ " from books where id =2002 ";
// 先查找第二个select的位置
int i1 = sql.indexOf("select", 1);
int i2 = sql.lastIndexOf("select");
// 给select前面插入一个-,便于后面截取
StringBuffer sb = new StringBuffer(sql);
sb.insert(i1, "-");
sb.insert(i2,"-");
String [] str = (sb.toString()).split("-");
for (String ss : str) {
System.out.println(ss);
}
}
A closer look is not difficult.
Welcome to pay attention to the public number:Xiongxiong's small classroom, Hahaha ~