通过 Java Web 在整个 MySQL 数据库中进行关键字搜索的推荐方法
Recommended method to Keyword Search in whole MySQL DB via JavaWeb
我正在尝试通过 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);
}
%>
现在我得到了大量查询。
我很困惑它是好是坏?!
考虑效率时,这种方法是不是很糟糕?
在查询建筑部分
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));
}
从那里我整理出了所需的数据。
-希望这对某些人有所帮助。
注意:尽管它对我有用,但我仍然相信它很天真
纠正我如果有更好的方法实现这个
我正在尝试通过 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);
}
%>
现在我得到了大量查询。 我很困惑它是好是坏?! 考虑效率时,这种方法是不是很糟糕?
在查询建筑部分
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));
}
从那里我整理出了所需的数据。
-希望这对某些人有所帮助。
注意:尽管它对我有用,但我仍然相信它很天真 纠正我如果有更好的方法实现这个