【问题标题】:is it possible to pull selected row from database by jsp and Servlets?是否可以通过 jsp 和 Servlet 从数据库中提取选定的行?
【发布时间】:2019-01-14 04:04:37
【问题描述】:

我正在使用以下查询来提取选定的数据

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 放在哪里...?

【问题讨论】:

    标签: jsp servlets jakarta-ee


    【解决方案1】:

    st 没有在你的代码中声明,它应该是PreparedStatement

    PreparedStatement  st = con.createStatement();
    

    请注意,您必须在代码中使用release all resources as PreparedStatement

    【讨论】:

      猜你喜欢
      • 2012-05-30
      • 1970-01-01
      • 2014-09-20
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多