Java oracle search

I have a drop-down menu that has a list of column names from a specific table in the database, and I have a text box in which the user can enter what he is looking for. First, the user selects a column from the drop-down menu and enters in the text field what he / she is looking for. I kind of lost how I can match these drop down list column names and text field row to look under a specific column in oracle database. Any sample code or suggestion would be helpful .. Thanks.

+3
source share
1 answer
   String colname = request.getParameter("colname");//get the column name from teh dropdown
   String value = request.getParameter("value");//get the value that the user entered

   PreparedStatement searchQuery = null;
   String searchString = String.format("Select * from yourtable where %s = ?", colname);

   //create a connection , say con
    searchQuery = con.prepareStatement(searchString);
    searchQuery.setString(1, value);

    ReultSet rs = searchQuery.executeQuery();

This solution is just a basic idea, so you need to modify it. If the columns you are looking for are of different types, you should serve this.

+2

All Articles