【问题标题】:Recommended method to Keyword Search in whole MySQL DB via JavaWeb通过 Java Web 在整个 MySQL 数据库中搜索关键字的推荐方法
【发布时间】:2021-01-23 11:34:53
【问题描述】:

我正在尝试通过 JSP 从我的整个 MySQL 数据库中实现 keyword search,如果我选择的方法效率低下,我会感到困惑:(

我已经阅读了information_schema 并发现所有列标​​签都在那里。

我已经尝试了下面的 SQL 语句来生成所有可能的查询:

SELECT CONCAT('SELECT * FROM ',table_schema,'.',table_name,
            ' WHERE ',column_name,' LIKE ','searchString',';')
      FROM information_schema.columns
      WHERE table_schema NOT IN ('information_schema','mysql','performance_schema')
      AND (column_type LIKE 'char(%'
      OR column_type LIKE 'varchar(%'
      OR column_type LIKE '%text')

并尝试使用 JSP 代码来获得所有可能的数据匹配。

<%
    String searchString =   "malayalam";
            searchString        =   "''%"+searchString+"%'' ";    
            ArrayList<String> queries =   new ArrayList<String>();
            String sql="SELECT CONCAT('SELECT * FROM ',table_schema,'.',table_name,"
                + "' WHERE ',column_name,' LIKE ','"+searchString+"',';')"
                + "FROM information_schema.columns "
                + "WHERE table_schema NOT IN ('information_schema','mysql','performance_schema')"
                + "AND (column_type LIKE 'char(%'"
                + "OR column_type LIKE 'varchar(%'"
                + "OR column_type LIKE '%text')";
            try{
                DBConInfoSchema db =   new DBConInfoSchema();
                ResultSet rs    =   db.getData(sql);
                while(rs.next()){
                    queries.add(rs.getString(1));
                }
                for(int i=0;i<queries.size();i++){
                    DBConInfoSchema dCon    =   new DBConInfoSchema();
                    ResultSet rsDemo        =   dCon.getData(queries.get(i));
                    if(rsDemo.next()){
                        out.print("<br/>Data found n query-"+i+" ->     "+queries.get(i));
                    }
                    dCon.DBClose();
                }
            }catch(Exception w){
                out.print("excep<br/>"+w);
            }
%>

现在我得到了巨大的查询列表。 我很困惑它是好是坏?! 考虑到效率,这种方法是不是很糟糕?

【问题讨论】:

    标签: java mysql jsp keyword-search


    【解决方案1】:

    在查询构建部分

    SELECT CONCAT('SELECT * FROM ',table_schema,'.',table_name,
                ' WHERE ',column_name,' LIKE ','searchString',';')
          FROM information_schema.columns
          WHERE table_schema NOT IN ('information_schema','mysql','performance_schema')
          AND (column_type LIKE 'char(%'
          OR column_type LIKE 'varchar(%'
          OR column_type LIKE '%text')
    

    我已经更新了行

    WHERE table_schema NOT IN ('information_schema','mysql','performance_schema')
    

     WHERE table_schema IN ('<my_table_name>')
    

    生成my_table_name中的所有搜索结果并保存到ArrayList并执行

    ArrayList<String> queries =   new ArrayList<String>();
    DBConInfoSchema db =   new DBConInfoSchema();
    ResultSet rs    =   db.getData(sql_statement);
    while(rs.next()){
      queries.add(rs.getString(1));
    }
    

    从那里我整理出所需的数据。

    -希望这可以帮助一些人。

    注意:尽管它对我有用,但我仍然相信它的幼稚 纠正我如果有更好的方法来实现这一点

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-05
      • 2014-11-27
      • 2011-12-02
      • 2019-01-12
      • 1970-01-01
      • 2015-03-12
      • 2012-06-21
      相关资源
      最近更新 更多