1.论文查询
定义实体类就不放了
查询语句:
package classes;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Dao {
public List<lunwenBean> getsize() throws SQLException{
List<lunwenBean> list=new ArrayList<>();
lunwenBean bean=null;
String sql="select * from xiangxi limit 2";
Connection conn =Dbutil.getConnection();
Statement st=null;
ResultSet rs=null;
try {
st=conn.createStatement();
st.executeQuery(sql);
rs=st.executeQuery(sql);
while(rs.next()) {
String title=rs.getString("title");
String zhaiyao=rs.getString("abstract");
String zuozhe=rs.getString("zuozhe");
String lianjie=rs.getString("link");
String time=rs.getString("time");
bean=new lunwenBean(title,zhaiyao,zuozhe,lianjie,time);
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
}
finally{
Dbutil.close(st, conn);
}
return list;
}
public List<lunwenBean> getselectlunwen(List<demBean> dl) throws SQLException{
List<lunwenBean> list=new ArrayList<>();
lunwenBean bean=null;
String sql="select * from xiangxi where ";
for(int i=0;i<dl.size();i++) {
if(dl.get(i).getXuanze().equals("题目")) {
dl.get(i).setXuanze("title");
}
else if(dl.get(i).getXuanze().equals("摘要")) {
dl.get(i).setXuanze("abstract");
}
else if(dl.get(i).getXuanze().equals("关键词")) {
dl.get(i).setXuanze("title");
}
else if(dl.get(i).getXuanze().equals("作者")) {
dl.get(i).setXuanze("zuozhe");
}
}
for(int i=0;i<dl.size();i++) {
if(i==0) {
sql=sql+" "+dl.get(i).getXuanze()+" ";
}
if(dl.get(i).getAndorno().endsWith("NOT")) {
if(dl.get(i).getJingmo().equals("精准")) {
sql=sql+"and "+dl.get(i).getXuanze()+" "+"!='"+dl.get(i).getNeirong()+"' ";
}
else if(dl.get(i).getJingmo().equals("模糊")) {
sql=sql+"and "+dl.get(i).getXuanze()+" "+"not like '%"+dl.get(i).getNeirong()+"%' ";
}
}
if(i!=0&&!dl.get(i).getAndorno().equals("NOT")) {
sql=sql+dl.get(i).getAndorno()+" "+dl.get(i).getXuanze()+" ";
}
if(!dl.get(i).getAndorno().equals("NOT")&&dl.get(i).getJingmo().equals("精准")) {
sql=sql+"='"+dl.get(i).getNeirong()+"' ";
}
else if(!dl.get(i).getAndorno().equals("NOT")&&dl.get(i).getJingmo().equals("模糊")) {
sql=sql+"like '%"+dl.get(i).getNeirong()+"%' ";
}
}
sql=sql+" order by time desc ";
System.out.println("SQL="+sql);
Connection conn =Dbutil.getConnection();
Statement st=null;
ResultSet rs=null;
try {
st=conn.createStatement();
st.executeQuery(sql);
rs=st.executeQuery(sql);
while(rs.next()) {
String title=rs.getString("title");
String zhaiyao=rs.getString("abstract");
String zuozhe=rs.getString("zuozhe");
String lianjie=rs.getString("link");
String time=rs.getString("time");
bean=new lunwenBean(title,zhaiyao,zuozhe,lianjie,time);
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
}
finally{
Dbutil.close(st, conn);
}
return list;
}
public static Map<String,Integer> getrc()
{
int tnumi=0;
String sql="select * from xiangxi ";
Map<String, Integer>map= new HashMap<String, Integer>();
Map<String, Integer>results= new LinkedHashMap<String, Integer>();
Connection conn =Dbutil.getConnection();
Statement st=null;
ResultSet rs=null;
try {
st=conn.createStatement();
st.executeQuery(sql);
rs=st.executeQuery(sql);
while(rs.next())
{
String keywords=rs.getString("title");
keywords=keywords.substring(1, keywords.length());
String[] split = keywords.split(" ");
for(int i=0;i<split.length;i++)
{
if(map.get(split[i])==null)
{
map.put(split[i],1);
}
else
{
map.replace(split[i], map.get(split[i])+1);
}
}
tnumi++;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println("of的个数为"+map.get("of")+"MAP个数"+map.size());
Dbutil.close(rs, st, conn);
map.entrySet()
.stream()
.sorted((p1, p2) -> p2.getValue().compareTo(p1.getValue()))
.collect(Collectors.toList())
.forEach(ele -> results.put(ele.getKey(), ele.getValue()));
return results;
}
}