?? sqlparserutil.java
字號:
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()];
// if (result.length == 1)
// {
// result[0] = temp.trim();
// return result;
// }
int i= 0;
while(st.hasMoreTokens())
{
String tempa = st.nextToken().trim();
if (tempa.indexOf(".")!= -1)
{
tempa = tempa.substring(tempa.indexOf(".")+1).trim();
}
if (tempa.indexOf(" as ")!= -1)
{
tempa = tempa.substring(tempa.indexOf(" as ")+4).trim();
}
if (tempa.indexOf(" ") != -1)
{
tempa = tempa.substring(tempa.lastIndexOf(" ")+1).trim();
}
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 ")).trim();
}
if (temp.indexOf(" ") != -1) {
temp = temp.substring(0, temp.indexOf(" ")).trim();
}
// System.out.println("tabel name = " + temp);
return new String[] {
temp};
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -