sqlparserutil.java
来自「bs_客户关系管理系统 每个例子文件夹都附有数据库表、程序源文件和一个war包」· Java 代码 · 共 66 行
JAVA
66 行
package myjdbc.util;
import java.util.StringTokenizer;
public final class SQLParserUtil {
//获得SQL语句中查询的列名
public static String[] parserSQL(String _sql ,String beginClause ,String endClause)
{
String sql = new String(_sql);
String temp = null;
int bg = sql.indexOf(beginClause);
int end = sql.indexOf(endClause);
if (end != -1)
temp = sql.substring(bg+beginClause.length()-1+2,end);
else
temp = sql.substring(bg+beginClause.length()-1+2);
// System.out.println("temp = " + temp);
if (temp.trim().equals("*"))
return null;
StringTokenizer st = new StringTokenizer(temp,",");
String[] result = new String[st.countTokens()];
int i= 0;
while(st.hasMoreTokens())
{
String tempa = st.nextToken().trim();
if (tempa.indexOf(".")!= -1)
{
tempa = tempa.substring(tempa.indexOf(".")+1);
}
if (tempa.indexOf("as")!= -1)
{
tempa = tempa.substring(tempa.indexOf("as")+3);
}
if (tempa.indexOf(" ") != -1)
{
tempa = tempa.substring(tempa.lastIndexOf(" ")+1);
}
result[i] = tempa;
i++;
// System.out.println(" tokens = " + tempa);
}
return result;
}
//获得SQL查询中的表名
public static String[] getTableName(String sql) {
int bg = sql.indexOf("from");
int end = sql.indexOf("where");
String temp = sql.substring(bg + 5);
if (end != -1)
temp = temp.substring(0, end).trim();
if (temp.indexOf("as") != -1) {
temp = temp.substring(0, temp.indexOf("as"));
}
if (temp.indexOf(" ") != -1) {
temp = temp.substring(0, temp.indexOf(" "));
}
// System.out.println("tabel name = " + temp);
return new String[] {
temp};
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?