Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java oracle search

I have dropdown menu that has list of column names from certain table in the database and I have textbox where user can type what one is looking for. User first selects the column from dropdown menu and types on textbox what s/he is looking for. I am kind of lost how can i match those dropdown column name and textbox string to look under specific column in oracle database.. Any sample code or suggestion would be helpful.. Thank you

like image 829
jack Avatar asked Jul 26 '26 21:07

jack


1 Answers

   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 only basic a idea so you have to modify to suit. If the columns that you are searching are of different types then you have to cater for that.

like image 183
Vincent Ramdhanie Avatar answered Jul 29 '26 10:07

Vincent Ramdhanie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!