-3

i am using the following query to pull selected data

String fetch_head = "select * from head_category where id = (?)";

but i don't know how to pull row by ResultSet and supply parameter using PreparedStatement same time.

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;
    }

Now where do I put the PreparedStatement...?

java
  • 33
  • 6

1 Answers1

0

st isn't declare in your code and it should be PreparedStatement

PreparedStatement  st = con.createStatement();

Notice that you must release all resources as PreparedStatement in your code

Ori Marko
  • 56,308
  • 23
  • 131
  • 233