5 |
import java.sql.PreparedStatement; |
import java.sql.PreparedStatement; |
6 |
import java.sql.ResultSet; |
import java.sql.ResultSet; |
7 |
import java.sql.SQLException; |
import java.sql.SQLException; |
8 |
|
import java.util.logging.Level; |
9 |
|
import java.util.logging.Logger; |
10 |
|
|
11 |
import javax.servlet.ServletException; |
import javax.servlet.ServletException; |
12 |
import javax.servlet.http.HttpServlet; |
import javax.servlet.http.HttpServlet; |
21 |
public class LocateStations extends HttpServlet { |
public class LocateStations extends HttpServlet { |
22 |
private static final long serialVersionUID = 1L; |
private static final long serialVersionUID = 1L; |
23 |
|
|
24 |
|
Logger logger = Logger.getLogger( LocateStations.class.toString() ); |
25 |
|
|
26 |
/** |
/** |
27 |
* @see HttpServlet#HttpServlet() |
* @see HttpServlet#HttpServlet() |
28 |
*/ |
*/ |
59 |
" SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, " + |
" SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, " + |
60 |
" earth_distance( ll_to_earth(latitude,longitude), ll_to_earth(?,?))::int AS calcdist " + |
" earth_distance( ll_to_earth(latitude,longitude), ll_to_earth(?,?))::int AS calcdist " + |
61 |
" FROM trainstations " + |
" FROM trainstations " + |
62 |
" WHERE latitude IS NOT NULL AND longitude IS NOT NULL " + |
" WHERE enabled = true AND latitude IS NOT NULL AND longitude IS NOT NULL " + |
63 |
" ) AS trainstations2 " + |
" ) AS trainstations2 " + |
64 |
"ORDER BY calcdist ASC " + |
"ORDER BY calcdist ASC " + |
65 |
"LIMIT 4 "; |
"LIMIT 4 "; |
74 |
"WHERE name ILIKE ? AND latitude IS NOT NULL AND longitude IS NOT NULL " + |
"WHERE name ILIKE ? AND latitude IS NOT NULL AND longitude IS NOT NULL " + |
75 |
"ORDER BY name "; |
"ORDER BY name "; |
76 |
stmt = conn.prepareStatement(SQL); |
stmt = conn.prepareStatement(SQL); |
77 |
stmt.setString(1, "%" + name + "%"); |
stmt.setString(1, name + "%"); |
78 |
break; |
break; |
79 |
default: |
default: |
80 |
throw new SQLException("not enough parameters"); |
// This should not be possible |
81 |
|
logger.severe("getStations(): default switch case"); |
82 |
} |
} |
83 |
|
|
84 |
|
|
126 |
} |
} |
127 |
|
|
128 |
if (request.getParameter("name") != null) { |
if (request.getParameter("name") != null) { |
129 |
name = request.getParameter("name"); |
name = request.getParameter("name").trim(); |
130 |
method = Requested.BY_NAME; |
method = Requested.BY_NAME; |
131 |
} |
} |
132 |
|
|
144 |
|
|
145 |
conn.close(); |
conn.close(); |
146 |
conn = null; |
conn = null; |
147 |
|
|
148 |
} catch (Exception e) { |
} catch (Exception e) { |
149 |
throw new ServletException(e); |
logger.log(Level.SEVERE, "Exception while finding stations", e); |
150 |
|
response.sendError(500); |
151 |
} finally { |
} finally { |
152 |
try { |
try { |
153 |
if (conn != null) |
if (conn != null) |