Java集和SQL查询

时间:2018-07-11 13:41:19

标签: java mysql sql

我有一个Set Area,我也有一个SQL查询,必须使用area。使用查询列表中所有区域的最简单方法是什么?

ps我知道查询应该看起来像

AND area IN('%New york%','%Las vegas%') 

2 个答案:

答案 0 :(得分:0)

您可以使用

public interface DummyInterface extends DBusInterface
{
    public static class Connect extends DBusSignal {
      public final String address;
      public Connect(String path, String address)
                             throws DBusException{
          super(path, address);
          this.address = address;
      }
    }
  public static class Disconnect extends DBusSignal {
    public final String address;
    public Disconnect(String path, String address)
                             throws DBusException {
       super(path, address);
       this.address = address;
      }
    }
  } package com.emcatron.dbus_test;

import org.freedesktop.dbus.DBusConnection;
import org.freedesktop.dbus.DBusSigHandler;
import org.freedesktop.dbus.DBusSignal;
import org.freedesktop.dbus.exceptions.DBusException;

public class Client implements DBusSigHandler {
    public void handle(DBusSignal s) {
        if (s instanceof DummyInterface.Connect)
            System.out.println("Got a connect for "
                    + ((DummyInterface.Connect) s).address);
        else if (s instanceof DummyInterface.Disconnect)
            System.out.println("Got a disconnect for "
                    + ((DummyInterface.Disconnect) s).address);
    }

    public static void main(String[] args) {
        System.out.println("Creating Connection");
        DBusConnection conn = null;
        try {
            conn = DBusConnection
                    .getConnection(DBusConnection.SYSTEM);
        } catch (DBusException DBe) {
            System.out.println("Could not connect to bus");
            System.exit(1);
        }
        System.out.println("Connected to system DBUS: " + DBusConnection.SYSTEM);
        int i = 0;
        for (String name: conn.getNames()) {
            System.out.format("name: %d: %s\n", i, name);
        }
        try {
            conn.addSigHandler(DummyInterface.Connect.class,
                    new Client());
            conn.addSigHandler(DummyInterface.Disconnect.class,
                    new Client());
        } catch (DBusException DBe) {
            conn.disconnect();
            System.exit(1);
        }
    }
}

OR

AND area in ('New york','Las vegas') 

答案 1 :(得分:0)

您真的需要%吗?这意味着您将接受除“纽约”或“拉斯维加斯”以外的其他任何值。

-使用休眠模式,您可以使用Restriction.in(“ area”,areaSet); 或在(:names)中使用HQLwhere名称

-您可以手动使用String sql =“ select * from name in(” StringUtils.join(set,',')+“)”;或者您可以使用流和set.stream()。collect(Collectors.joining(','))