我有两个表格stops
和arrivaltimes
我想在查询中添加正确的拼写'单面'或sat
或sun
什么是最好的方式在java中管理它?例如今天是星期一,如果停止的名称ABC
工作日为Monday
且当前时间等于10:43
到达时间我想要获得路线号9
此查询工作正常,但我不知道如何拼写:
SELECT route from arrivaltimes
INNER JOIN stops ON arrivaltimes.stop_id=stops.stop_id
WHERE weekday = "+ day +"
and time_format(arrivaltime,'%H:%i')= time_format(curtime() ,'%H:%i')
and name LIKE stop_name
我的代码:
Connection con = DriverManager.getConnection(host, user, password);
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK);
// Create a statement
Statement stt = con.createStatement();
DatabaseMetaData dbm = con.getMetaData();
ResultSet stopsExist = dbm.getTables(null, null, "stops", null);
if (stopsExist.next()) {
// the stops and arrrivaltimes tables exist.
PreparedStatement preparedLatLong = con
.prepareStatement("SELECT lat, longi from stops");
ResultSet rsLatLong = preparedLatLong.executeQuery();
while (rsLatLong.next()) {
double lat_stop = rsLatLong.getDouble("lat");
double lon_stop = rsLatLong.getDouble("longi");
double distStops = haversineDistance(latD, longD, lat_stop,
lon_stop);
if (distStops <= 10) {
String stop_name = rsLatLong.getString("name");
PreparedStatement preparedTime = con
.prepareStatement("SELECT route from arrivaltimes INNER JOIN stops"
+ " ON arrivaltimes.stop_id=stops.stop_id "
+ "WHERE weekday = "+ day +" and time_format(arrivaltime,'%H:%i')= time_format(curtime() ,'%H:%i') and name LIKE"
+ stop_name);
ResultSet rsArrivaletime = preparedTime.executeQuery();
routeList = new ArrayList<Integer>();
while (rsArrivaletime.next()) {
int route = rsArrivaletime.getInt("route");
routeList.add(route);
}
}
break;
}