我正在使用以下查询提取所选数据
String fetch_head = "select * from head_category where id = (?)";
但是我不知道如何同时使用ResultSet和使用PreparedStatement提供参数。
public ArrayList fetch_selected() {
ArrayList arrayList = new ArrayList();
try {
connectionFactory cf = new connectionFactory();
con = cf.getcon();
st = con.createStatement();
rs = st.executeQuery(fetch_head);
while (rs.next()) {
// it only fetches all
}
} catch (Exception e) {
e.printStackTrace();
}
return arrayList;
}
现在我应该在哪里放置PreparedStatement ...?
答案 0 :(得分:0)
st
未在您的代码中声明,应该为PreparedStatement
PreparedStatement st = con.createStatement();
请注意,您必须在代码中release all resources as PreparedStatement