⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlparserutil.java

📁 bs_客户关系管理系统 每个例子文件夹都附有数据库表、程序源文件和一个war包(或者jar包)。如果是cs结构的
💻 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()];
      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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -