简体   繁体   English

如何从函数将数据检索到jsp文件中的下拉列表框中

[英]How can I retrieve data to a drop down list box in my jsp file from a function

How can I retrieve data from SQL database (specifically from a column) to drop down list box in my JSP file? 如何从SQL数据库(特别是从一列)中检索数据以下拉JSP文件中的列表框? but I want to retrieve this data from a function in a .java file and the to the JSP list box so the order will be: 但我想从.java文件中的函数中检索此数据,并将其检索到JSP列表框中,因此顺序为:

A function in my java file that retrieve the data from sql DB (specifically from a column) and the show it in my jps list box? 我的java文件中的一个函数,该函数从sql DB(特别是从列)中检索数据并将其显示在jps列表框中?

this will the function in java file 这将在java文件中的功能

here is my code: 这是我的代码:

public String getc_Condicion(){
    String query = "";

    String c_condicion = new String();
        query = "select C_Condicion_Beca from Bca_Condicion_Beca";
        try{
            st = con.createStatement();
            rs = st.executeQuery(query);

            while (rs.next()){
                c_condicion = rs.getString("C_Condicion_Beca");
               }
        }
        catch(SQLException e){
        System.out.println("Error al obtener los datos: "+e.getMessage());

        }

    return c_condicion;
}

Are you looking for this? 您在找这个吗? This may not be Best design wise though. 但是,这可能不是最佳设计明智的选择。

public String[] getcDataCondicion(){
    String query = "";

    String[] cDataCondicion= new String[100];
        query = "select C_Condicion_Beca from Bca_Condicion_Beca";
        try{
            st = con.createStatement();
            rs = st.executeQuery(query);
            int i=0;
            while (rs.next()){
                cDataCondicion[i] = rs.getString("C_Condicion_Beca");
                 i++;
               }
        }
        catch(SQLException e){
        System.out.println("Error al obtener los datos: "+e.getMessage());

        }

    return cDataCondicion;
}

<%  

  YourClass c= new YourClass();
String[] result=c.getcDataCondicion();
%>

<Select>
<%
  for(int i=0;i<result.length;i++){
%>
 <Option>result[i]</ Option>
<% } %>
</select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将值从下拉列表和文本框传递到JSP中的JavaScript - passing values from drop down list and text box to JavaScript in JSP 如何使用java / jsp从Web表单中的特定下拉框中提取值列表 - how to extract the list of values from a specific drop down box in a web form, using java/jsp 如何将分隔符添加到我的下拉列表(微调器)? - How can i add divider to my drop down list (spinner)? 如何从数据库动态填充我的JSP页面中的下拉列表? - How to dynamically populate the drop down list in my JSP page from the database? 如何将“下拉”列表的数据从JSP存储到我们的MySql数据库? - How to store data of “Drop-down” list from JSP to our MySql Database? 如何从数据库中填充JSP中的下拉列表 - How to populate drop down list in JSP from a database JSP-日期从下拉列表中的对象 - JSP - Date objects from drop down list 如何显示一个表中下拉框的第一个值和另一个表中相同下拉列表的其他值 - How can I display first value of drop down box from one table and other values of same drop down from another table 下拉框在 JSP 中不起作用 - Drop Down Box not working in JSP JSP 在下拉框中使用数组列表的内容 - JSP use contents of an array list in a drop down box
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM