--- android/TrainInfoService/src/dk/thoerup/traininfoservice/StationDAO.java 2010/10/01 05:30:32 1145 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java 2011/05/02 16:21:37 1417 @@ -1,4 +1,4 @@ -package dk.thoerup.traininfoservice; +package dk.thoerup.traininfoservice.db; import java.sql.Array; import java.sql.Connection; @@ -9,7 +9,7 @@ import java.util.logging.Logger; import dk.thoerup.android.traininfo.common.StationBean; -import dk.thoerup.android.traininfo.common.StationBean.StationEntry; +import dk.thoerup.android.traininfo.common.StationEntry; public class StationDAO { @@ -165,7 +165,10 @@ return result; } - //the "hack" with max 0.4 degrees latitude and 0.75 degrees longitude is only valid since we only service danish trains, + //Latitude (horizonal), longitude(vertical) so + // 1 degree latitude is ~ 111320 meters, since the distance between the horizonal lines is always the same + // 1 degree longitude is ~111320 meters at equator but gets shorter as we get closer to the poles. + // the "hack" with max 0.4 degrees latitude and 0.75 degrees longitude is only valid since we only service danish trains, // in denmark 0.4dg latitude ~ 44km, 0.75dg longitude ~ 47km // the ultra fast method (and only slightly inaccurate as long as we only cover a limited geographically area) @@ -255,6 +258,7 @@ return result; } + @Deprecated public static String getStationName(int stationID) { String station = ""; @@ -277,7 +281,43 @@ return station; } + + public StationEntry getSimpleByName(String name) throws SQLException { + String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, 0.0 " + + "FROM trainstations " + + "WHERE name = ? AND enabled = true " + + "LIMIT 1 "; + + StationBean result; + Connection conn = null; + PreparedStatement stmt = null; + ResultSet res = null; + try { + conn = DBConnection.getConnection(); + stmt = conn.prepareStatement(SQL); + + stmt.setString(1, name ); + + res = stmt.executeQuery(); + result = convertResultset(res); + + } finally { + if (res != null) + res.close(); + if (stmt != null) + stmt.close(); + if (conn!= null) + conn.close(); + } + + if (result.entries.size() == 1) { + return result.entries.get(0); + } else { + return null; + } + } + @Deprecated public int getIdByName(String name) throws SQLException { String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, 0.0 " + "FROM trainstations " +