📄 quicksearchmanager.java
字号:
package com.gecb.mcompanion.web.db;import java.sql.*;/**** @author student*/public class QuickSearchManager extends DBManager { private float latitude ; private float longitude ; public QuickSearchManager() { super(); } public QuickSearchManager(float latitude,float longitude) { this.latitude = latitude ; this.longitude = longitude ; } public String searchLocations(String name, String keywords) { String res = ""; int count=0; // String query ="SELECT ((ACOS(SIN("+ latitude+"* PI() / 180) * SIN(lat * PI() / 180) + COS("+latitude+" * PI() / 180) * COS(lat *PI() / 180) * COS(("+longitude+"- log) * PI() / 180)) * 180 / PI()) * 60* 1.1515) AS distance,name,description,place,lat,log FROM location HAVING distance<='10' ORDER BY distance ASC"; String query = "select name,description,place,lat,log fromlocation where name like '%"+name+"%' and speciality like '%"+keywords+"%'"; System.out.println(query); try { ResultSet rs = getStatement().executeQuery(query); while (rs.next()) { res += rs.getString(1) + ":" + rs.getString(2) + ":" + rs.getString(3) + ":" + rs.getString(4) + ":" + rs.getString(5) + ":" ; res += "#"; } } catch (Exception e) { e.printStackTrace(); } return res; } public String searchLocations(String name) { String res = ""; int count = 0; String query = "select name,description,place,lat,log fromlocation where name like '%" + name + "%' or speciality like '%" + name +"%'"; System.out.println(query); try { ResultSet rs = getStatement().executeQuery(query); while (rs.next()) { res += rs.getString(1) + ":" + rs.getString(2) + ":" + rs.getString(3) + ":" + rs.getString(4) + ":" + rs.getString(5) + ":" ; res += "#"; } } catch (Exception e) { e.printStackTrace(); } return res; } public String searchLocations() { String res = ""; int count = 0; String query ="SELECT ((ACOS(SIN("+ latitude+"* PI() / 180) *SIN(lat * PI() / 180) + COS("+latitude+" * PI() / 180) * COS(lat * PI()/ 180) * COS(("+longitude+"- log) * PI() / 180)) * 180 / PI()) * 60 *1.1515) AS distance,name,description,place,lat,log FROM location HAVINGdistance<='10' ORDER BY distance ASC"; //String query = "select * from location "; try { ResultSet rs = getStatement().executeQuery(query); while (rs.next()) { res += rs.getString(2) + ":" + rs.getString(3) + ":" + rs.getString(4) + ":" + rs.getString(5) + ":" + rs.getString(6) + ":" ; res += "#"; } } catch (Exception e) { e.printStackTrace(); } return res; }public String searchHospitals(String name,String keyword) { String query="select hospital_name,hospital_type,hospital_speciality,city,latitude,longitude from hospital,address where hospital.address_id=address.address_id and hospital_name like '%"+name.toUpperCase()+"%' and hospital_type like '%"+keyword.toUpperCase()+"%'"; String res=""; System.out.println(query); try{ ResultSet rs=getStatement().executeQuery(query); /* if(rs==null) { res="notfound"; res+="#"; return res; }*/ while(rs.next()) { System.out.println("inside while"); res += rs.getString(1) + ":" + rs.getString(2) + ":"+rs.getString(3) + ":" + rs.getString(4) + ":"+rs.getString(5) + ":" + rs.getString(6) + ":"; res+="#"; } if(res.equals("")) { res +="notfound #"; } } catch(Exception e) { e.printStackTrace(); } return res;} public String searchHospitals(String name) { String res = ""; int count = 0; String query = "select hospital_name,hospital_type,hospital_speciality,city,latitude,longitude from hospital,address where hospital.address_id=address.address_id and hospital_name like '%" + name.toUpperCase() + "%' or hospital_type like '%" + name.toUpperCase() + "%'"; try { ResultSet rs = getStatement().executeQuery(query); while (rs.next()) { res += rs.getString(1) + ":" + rs.getString(2) + ":" + rs.getString(3) +":"+ rs.getString(4) + ":" + rs.getString(5) + ":" +rs.getString(6); res += "#"; } if(res.equals("")) { res="notfound #"; } } catch (Exception e) { e.printStackTrace(); } System.out.println(res); return res;}public String searchHospitals(){ String res = ""; int count = 0; String query = "select hospital_name,hospital_type,hospital_speciality,city,latitude,longitude from hospital,address where hospital.address_id=address.address_id"; try { ResultSet rs = getStatement().executeQuery(query); while (rs.next()) { res += rs.getString(1) + ":" + rs.getString(2) + ":" + rs.getString(3) +":"+ rs.getString(4) + ":" + rs.getString(5) + ":" +rs.getString(6)+":"; res += "#"; } if(res.equals("")) { res +="notfound #"; } } catch (Exception e) { e.printStackTrace(); } return res;}public String searchInstitutions(String name, String keyword) { String query = "select name,courses,facilities,city,latitude,longitude from institution,address where institution.address_id=address.address_id and name like '%"+name.toUpperCase()+"%' and courses like '%"+keyword.toUpperCase()+"%'"; String res=""; System.out.println(query); try { ResultSet rs = getStatement().executeQuery(query); while (rs.next()) { res += rs.getString(1) + ":" + rs.getString(2) + ":" + rs.getString(3) + ":" + rs.getString(4) + ":" + rs.getString(5) + ":" + rs.getString(6) +":"; res += "#"; } if(res.equals("")) { res +="notfound #"; } } catch (Exception e) { e.printStackTrace(); } return res;}public String searchInstitutions(String name) { String res = ""; int count = 0; String query = "select name,courses,facilities,city,latitude,longitude from institution,address where institution.address_id=address.address_id and name like '%" + name.toUpperCase() + "%' or courses like '%" + name.toUpperCase() + "%'"; try { ResultSet rs = getStatement().executeQuery(query); while (rs.next()) { res += rs.getString(1) + ":" + rs.getString(2) + ":" + rs.getString(3) + ":" + rs.getString(4) + ":" + rs.getString(5) + ":" + rs.getString(6) + ":"; res += "#"; } if(res.equals("")) { res="notfound"; res+="#"; } } catch (Exception e) { e.printStackTrace(); } return res;}public String searchInstitutions() { String res = ""; int count = 0; String query = "select name,courses,facilities,city,latitude,longitude from institution,address where institution.address_id=address.address_id"; try { ResultSet rs = getStatement().executeQuery(query); while (rs.next()) { res += rs.getString(1) + ":" + rs.getString(2) + ":" + rs.getString(3) +":"+ rs.getString(4) + ":" + rs.getString(5) + ":" +rs.getString(6)+":"; res += "#"; } if(res.equals("")) { res="notfound"; res+="#"; } } catch (Exception e) { e.printStackTrace(); } return res;}public String searchAirports(String name,String keyword){ String res =""; int count =0; String query = "select airport_name,airport_type,SPECIALITIES,city,latitude,longitude from airport,address where airport.address_id=address.address_id where airport_name like '%"+name.toUpperCase()+"%' and airport_type like '%"+keyword.toUpperCase()+"%'"; System.out.println(query); try{ ResultSet rs=getStatement().executeQuery(query); while(rs.next()) { System.out.println("inside while"); res += rs.getString(1) + ":" + rs.getString(2) + ":"+rs.getString(3) + ":" + rs.getString(4) + ":"+rs.getString(5) + ":" + rs.getString(6) + ":"; res+="#"; } if(res.equals("")) { res="notfound"; res+="#"; } } catch(Exception e) { e.printStackTrace(); } return res;}public String searchAirports(String name){ String res = ""; String query = "select airport_name,airport_type,SPECIALITIES,city,latitude,longitude from airport,address where airport.address_id=address.address_id where airport_name like '%"+name.toUpperCase()+"%' or airport_type like '%"+name.toUpperCase()+"%'"; System.out.println(query); try{ ResultSet rs=getStatement().executeQuery(query); while(rs.next()) { System.out.println("inside while"); res += rs.getString(1) + ":" + rs.getString(2) + ":"+rs.getString(3) + ":" + rs.getString(4) + ":"+rs.getString(5) + ":" + rs.getString(6) + ":"; res+="#"; } if(res.equals("")) { res="notfound"; res+="#"; } } catch(Exception e) { e.printStackTrace(); } return res;}public String searchAirports(){ String res =""; String query = "select airport_name,airport_type,SPECIALITIES,city,latitude,longitude from airport,address where airport.address_id=address.address_id"; System.out.println(query); try{ ResultSet rs=getStatement().executeQuery(query); while(rs.next()) { res += rs.getString(1) + ":" + rs.getString(2) + ":"+rs.getString(3) + ":" + rs.getString(4) + ":"+rs.getString(5) + ":" + rs.getString(6) + ":"; res+="#"; } if(res.equals("")) { res="notfound"; res+="#"; } } catch(Exception e) { e.printStackTrace(); } return res;}public String searchShops(String name, String keyword) { String res = ""; int count = 0; String query = "select shop_name,shop_type,facilities,city,latitude,longitude from shop,address where shop.address_id=address.address_id and shop_name like '%"+name.toUpperCase()+"%' and shop_type like '%"+keyword.toUpperCase()+"%'"; System.out.println(query); try { ResultSet rs = getStatement().executeQuery(query); while (rs.next()) { res += rs.getString(1) + ":" + rs.getString(2) + ":"+rs.getString(3) + ":" + rs.getString(4) + ":"+rs.getString(5) + ":" + rs.getString(6) + ":"; res += "#"; } if(res.equals("")) { res="notfound"; res+="#"; } } catch (Exception e) { e.printStackTrace(); } return res;} public String searchShops(String name) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -