开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜