开发者

Java oracle search

开发者 https://www.devze.com 2023-03-07 21:51 出处:网络
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 a

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 textbo开发者_如何学Gox string to look under specific column in oracle database.. Any sample code or suggestion would be helpful.. Thank you


   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.

0

精彩评论

暂无评论...
验证码 换一张
取 消