Preparedstatement java

时间:2013-04-10 09:00:32

标签: java

我想寻找与枚举相匹配的东西:分裂: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()); 

我什么都没得到

1 个答案:

答案 0 :(得分:0)

代码正在尝试使用String设置Enum参数。它应该获得Enum的String值并传递给setString方法。

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