📄 quicksearchmanager.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.horizongroup.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 from location 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 from location 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 HAVING distance<='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 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,specialities,place,lat,log FROM hospital HAVING distance<='10' ORDER BY distance ASC and where name like '%" + name + "%' and specialities like '%" + keywords + "%'"; //String query = "select * from hospital where hospital_name like '%" + name + "%' and hospital_type like '%" + keywords + "%'"; String query ="select * from hospital where hospital_name='SCTIMST'"; System.out.println(query); try { ResultSet rs = getStatement().executeQuery(query); while(rs.next()) { //int aid=Integer.parseInt(rs.getString(2)); //query="select city,latitude,longitude from address where address_id ="+aid; //rs1 = getStatement().executeQuery(query); res += rs.getString(2) + ":" + rs.getString(3) + ":" + rs.getString(4) +":"+ rs.getString(5) + ":"; System.out.println("response="+res); //rs1.close(); // out.println(res); } rs.close(); rs = getStatement().executeQuery(query); while(rs.next()){ System.out.println("rs"); String aid=rs.getString(2); System.out.println("Address id:"+aid); query="select city,latitude,longitude from address where address_id ="+aid; System.out.println(query); ResultSet rs1 = getStatement().executeQuery(query); String res1=rs1.getString(1)+":"+rs1.getString(2)+":"+rs1.getString(3)+":"; res1+="#"; System.out.println("Resp:"+res); } } catch (Exception e) { e.printStackTrace(); } return res;} */ public String searchHospitals(String name,String keyword) { String query="select * from hospital where hospital_name like '%"+name+"%' and hospital_type like '%"+keyword+"%'"; String res=""; String finalres=""; System.out.println(query); try{ ResultSet rs=getStatement().executeQuery(query); int i=0; int address[]=new int[20]; while(rs.next()) { System.out.println("inside while"); address[i]=Integer.parseInt(rs.getString(2)); i++; res += rs.getString(3) + ":" + rs.getString(4) + "&"; } String [] res1=res.split("&"); for(int k=0;k<res1.length;k++) { System.out.println("res1"+res1[k]); } for(int n=0;n<=i;n++) { query="select city,latitude,longitude from address where address_id="+address[n]; System.out.println("inside query="+query); rs=getStatement().executeQuery(query); while(rs.next()) { finalres+=res1[n]+":"+rs.getString(1)+":"+rs.getString(2)+":"+rs.getString(3)+":"; finalres+="#"; } } System.out.println("final rs"+finalres); }catch(Exception e) { e.printStackTrace(); } return finalres; } public String searchHospitals(String name) { String res = ""; int count = 0; String query = "select name, specialities ,place ,lat ,log from hospital where name like '%" + name + "%' or specialities like '%" + name + "%'"; 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(); } System.out.println(res); return res; }public String searchHospitals(){ String res = ""; int count = 0; //String query = "select name, specialities ,place ,lat ,log from hospital where name like '%" + name + "%' and specialities like '%" + keywords + "%'"; //String query = "select name, specialities ,place ,lat ,log from hospital "; 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,specialities,place,lat,log FROM hospital HAVING distance<='10' ORDER BY distance ASC"; try { ResultSet rs = getStatement().executeQuery(query); while (rs.next()) { // out.println("Inside rs.next()"); res += rs.getString(2) + ":" + rs.getString(3) + ":" + rs.getString(4) +":"+ rs.getString(5) + ":" + rs.getString(6) + ":" ; res += "#"; // out.println(res); } } catch (Exception e) { e.printStackTrace(); } return res;}public String searchInstitutions(String name, String keywords) { String res = ""; int count = 0; String query = "select name,place,courses,facilities,lat,log from institution where name='"+name+"'and (courses like '%"+keywords+"%' or facilities like '%"+keywords+"%')"; System.out.println(query); // 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,place,courses,facilities,lat,log FROM institution HAVING distance<='10' ORDER BY distance ASC"; 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 += "#"; } } catch (Exception e) { e.printStackTrace(); } return res;}public String searchInstitutions(String name) { String res = ""; int count = 0; String query = "select name,place,courses,facilities,lat,log from institution where name='"+name+"'or(courses like'%"+name+"%' or facilities like '%" + name + "%')"; 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 += "#"; } } catch (Exception e) { e.printStackTrace(); } return res;}public String searchInstitutions() { 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,place,courses,facilities,lat,log FROM institution HAVING distance<='10' ORDER BY distance ASC"; System.out.println(query); // String query = "select name,place,courses,facilities,lat,log from institution "; try { ResultSet rs = getStatement().executeQuery(query); while (rs.next()) { res += rs.getString(2)+":" + rs.getString(4)+":"+rs.getString(3)+":"+rs.getString(6) + ":" + rs.getString(7) + ":" ; //+ rs.getString(7)+":"; res += "#"; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -