我正试图通过JSP从我的整个keyword search数据库中实现一个MySQL,我很困惑我选择的方法是否效率低下:
我读过关于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);
}
%>现在我得到了大量的查询列表。我很困惑它是好是坏?!在考虑效率的时候,这种方法是不是不好呢?
发布于 2021-03-19 10:05:38
在查询生成部分中。
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));
}从那里我整理出所需的数据。
-Hope,这可能会对某些人有所帮助。
注:即使它对我有用,我仍然相信它的天真,纠正我,如果有更好的方法,你做到这一点
https://stackoverflow.com/questions/65858718
复制相似问题