【问题标题】:How can I retrieve data to a drop down list box in my jsp file from a function如何从函数将数据检索到我的 jsp 文件中的下拉列表框
【发布时间】:2013-04-24 16:40:32
【问题描述】:

如何从 SQL 数据库(特别是从列中)检索数据到我的 JSP 文件中的下拉列表框?但我想从 .java 文件中的函数和 JSP 列表框中检索此数据,因此顺序为:

我的 java 文件中的一个函数,它从 sql DB(特别是从列中)检索数据并将其显示在我的 jps 列表框中?

这将是java文件中的函数

这是我的代码:

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

【问题讨论】:

    标签: java sql jsp


    【解决方案1】:

    你在找这个吗?不过,这可能不是最好的设计。

    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>
    

    【讨论】:

      猜你喜欢
      • 2014-06-22
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      • 2018-03-21
      • 2014-08-13
      • 2020-09-09
      • 2015-04-05
      • 1970-01-01
      相关资源
      最近更新 更多