0

我想寻找与枚举匹配的东西: Divisions:U6,U7,U8... 当我这样做时它会起作用。

public ArrayList<Training> zoekTrainingen(Ploegen p) throws
        ApplicationException {

    ArrayList<Training> tr = new ArrayList<>();
    Connection conn = ConnectionManager.getConnection(driver,
            dburl, login, paswoord);
    try (PreparedStatement stmt = conn.prepareStatement(
            "select * from trainingen");) {
        stmt.execute();
        ResultSet r = stmt.getResultSet();

        while (r.next()) {
        ---

        }
    } catch (SQLException sqlEx) {
        throw new ApplicationException("");
    }
    finally {
        return tr;
    }
}

    }

但是当我这样做时:

try (PreparedStatement stmt = conn.prepareStatement(
            "select * from trainingen where Divsion = ?");) {
            stmt.setString(1, p.getDivision()); 

我什么都得不到

4

1 回答 1

0

该代码正在尝试String使用Enum. 它应该获取StringEnum 的值并传递给setString方法。

try (PreparedStatement stmt = conn.prepareStatement(
            "select * from trainingen where Divsion = ?");) {
            stmt.setString(1, p.getDivision().toString()); 
于 2013-04-10T09:03:17.097 回答