在查询中获取正确的一天拼写

时间:2015-05-11 08:26:15

标签: java mysql sql

我有两个表格stopsarrivaltimes我想在查询中添加正确的拼写'单面'或satsun什么是最好的方式在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

enter image description here

enter image description here

我的代码:

    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;
        }

0 个答案:

没有答案