Java oracle搜索

Java oracle搜索,java,oracle,search,drop-down-menu,Java,Oracle,Search,Drop Down Menu,我有一个下拉菜单,其中有数据库中某个表中的列名列表,还有一个文本框,用户可以在其中键入要查找的内容。用户首先从下拉菜单中选择列,并在文本框中键入他/她要查找的内容。我有点不知所措,我怎样才能匹配那些下拉式列名和文本框字符串,以便在oracle数据库中的特定列下查找。。任何示例代码或建议都会有所帮助。。多谢各位 String colname = request.getParameter("colname");//get the column name from teh dropdown

我有一个下拉菜单,其中有数据库中某个表中的列名列表,还有一个文本框,用户可以在其中键入要查找的内容。用户首先从下拉菜单中选择列,并在文本框中键入他/她要查找的内容。我有点不知所措,我怎样才能匹配那些下拉式列名和文本框字符串,以便在oracle数据库中的特定列下查找。。任何示例代码或建议都会有所帮助。。多谢各位

   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();

这个解决方案只是一个基本的想法,所以你必须修改以适应。如果您正在搜索的列属于不同的类型,那么您必须满足这一要求。

这是Swing应用程序还是web应用程序?+1但我想指出的是,这会使应用程序暴露于SQL注入漏洞。还应注意验证请求参数。同意SQL注入漏洞。如果对
colname
中的值进行验证,以确认它实际上是一个列,则效果会更好。检查
USER\u TAB\u COLUMNS
视图将是一个好主意,或者一个可接受列名的枚举列表可能更好。