Try making the following changes to your Java code -- the output should give
you some clues about what's going wrong.

-Brian

On Sun, Mar 13, 2011 at 11:52 PM, JavaNoobie87 <vivek...@enzentech.com>wrote:

> Hi All,
> Im developing a Crud example using Struts 2 where im in the need to load
> values for a dropdown box dynamically from a database . However im just
> getting a empty dropdown now .
> The JSP code snippet is as below.
>                DomainType
>
>
>
> The action class and DAO for the same function are as below.
>
> Action.
> public String loadDomainType(){
>                // Class used to get the domaintype from domaintype table
>                System.out.println("my logging statement");
>                String result=SUCCESS;
>                try {
>                        System.out.println("Inside loaddomaintype");
>                        List loadDomainType = DomainDAO.loadDomainType();
>                        dtList=loadDomainType;
>
System.out.println("dtList length: " + dtList.length);

>                } catch (Exception e) {
>                        // TODO Auto-generated catch block;
>                        result=ERROR;
>                        e.printStackTrace();
>                }
>
> DAO Class--
> public static List loadDomainType() throws Exception {
>                Connection con = null;
>                PreparedStatement stmt = null;
>                ResultSet rs = null;
>                System.out.println("loadDomaintype DAO");
>                DomainBean bean = new DomainBean();
>                ArrayList dtList = new ArrayList();
>
>                try {
>                        con= DBConnector.getConnection();
>                        if (con != null){
>                                System.out.println("Connected");
>                                String query= " SELECT
> CODE,DESCRIPTION,OBJECTID FROM DOMAINTYPE " ;
>                                stmt = con.prepareStatement(query);
>                                rs = stmt.executeQuery();
>                                System.out.println("inside loadDomainType");
>                                while (rs.next()){
>
bean = new DomainBean();

>                                        bean.setCode(rs.getString("CODE"));
>
>  bean.setDescription(rs.getString("DESCRIPTION"));
>
>  bean.setObjid(rs.getInt("OBJECTID"));
>                                        dtList.add(bean);
>
System.out.println("Adding bean to list: " + bean.getDescription());

>
>
>                                }
>
>                        }
>                } catch (SQLException sqe) {
>                        sqe.printStackTrace();
>
>                } finally {
>                        DBConnector.closeResultSet(rs);
>                        DBConnector.closeStatement(stmt);
>                        DBConnector.closeConnection(con);
>                }
>
>                return dtList;
>        }
>
>
> --
> View this message in context:
> http://struts.1045723.n5.nabble.com/loading-Dropdown-dynamically-from-database-tp3555884p3555884.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>

Reply via email to