1.一次性查询数据库表中 所有用于作为关键字搜索字段的所有记录,
public static ResultSet getResult(String storeId) throws Exception {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url = "jdbc:sqlserver://19.***.178.***:1433;DatabaseName=***";
String userName = "sa";
String password = "*********";
Connection conn = DriverManager.getConnection(url, userName, password);
Statement stmt = conn.createStatement();
String sql = "select * from (select row_number()over(ORDER BY getdate() desc) as indexId ," +
"u.pkid as unitId, u.Name as unitName,u.Address," +
"u.Tags as unitTags,u.Introduction, e.Content,a.Value," +
"ut.typeName as typeName from Unit u " +
"left join UnitEvaluate e on e.UnitID = u.pkid left join " +
"UnitAttribute a on a.UnitId=u.pkid left join " +
"(select ty.name as typeName,a.unitid as unitid from UnitType ty " +
"left join Attribute b on b.unitTypeId= ty.pkid " +
"left join AttributeValue v on v.AttributeId= b.pkid " +
"right join UnitAttribute a on a.AttributeValueID= v.pkid) as ut on " +
"ut.unitid = u.pkid) newView";
ResultSet rs = stmt.executeQuery(sql + " where newView.indexId > '" + storeId + "'order by newView.indexId");
return rs;
}
ps:多表查询 工作量最大的地方 烧脑
==================================
sql 结果集 测试数据24336条
24327 6CA25FF0-73D7-47DD-9D14-FFF3E3088D97 文华羽绒 佛山市顺德区大良高坎路近涌街21号 羽绒服,鹅绒,鸭绒,灰绒,白绒, <span style="font-size:18px;"> 本店销售各类型羽绒服装,欢迎前来选购。</span> NULL 服装店 购在大良
24328 7AC1A5E6-14B6-4BF1-85CF-FFF45AD905CB 大良东铁装饰材料店 佛山市顺德区大良东康路珠江楼B座115 NULL NULL NULL 服装店 购在大良
24329 315D155A-EE3D-4ABD-9042-FFF572BF1721 海诺贸易有限公司 佛山市顺德区大良新桂路和桂街72号 NULL NULL NULL 综合性贸易企业 企在大良
24330 89CB91A5-48D2-4390-8D8F-FFF61C375C42 大良顺峰五金塑料制品厂 顺德区大良街道凤翔工业区30号-1-C1 顺德区大良街道凤翔工业区30号-1-C1 NULL NULL 办公机械五金工具 企在大良
24331 79C09F8C-DF6D-4EFD-8C9E-FFF83F3E0C99 万皆贸易有限公司 佛山市顺德区大良大门沙圩队工业用地办公楼2楼之三 NULL NULL NULL 综合性贸易企业 企在大良
24332 AF99B46C-1B45-4421-9A17-FFF8C266A6B4 仅一味<body ONLOAD=alert(42873)> 顺德区大良购书中心 仅一味美食 串串香 麻辣烫 酸辣粉 88888