skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Thursday, November 1, 2012

Code to Populate Dropdown from a DB

Posted by Raju Gupta at 12:00 AM – 0 comments
 

Using this Java snippet the users can Populate Dropdown from a DB   

//Code to Populate Dropdown from a DB//
//In JSP//
<div id="bodydiv" align="center" >
    <select name=" Name" onchange="this.form.submit();">
     <option name="Router Name" value="0">--------select--------</option>
     <%
     GetXRouter dao = new GetXRouter();
     ArrayList ReList = dao.retreiveRname();
     for (int i = 0; i < ReList.size(); i++) {
    %>
     <option name="RName" value="<%=ReList.get(i)%>"><%=ReList.get(i)%></option>
     <%
     }
    %>
    </select>

//IN Java Class File//
public class GetList {
 static Connection conn = null;
 static Statement st = null;
 static ResultSet rs = null;
 static DBConnection db;

 
 @SuppressWarnings({ "rawtypes", "unchecked" })
 public ArrayList retreiveIname(String Rname) throws SQLException {
  Connection conn;
  DBConnection db = new DBConnection();
  conn = db.getConnection();
  Statement st;
  st = conn.createStatement();
  ResultSet rs = st.executeQuery("select tt.Y_nm from Z.Z_X_Y_cfg tt where tt.active = 'A' and tt.X_nm = '"+Rname+"' ");
  ArrayList IList = new ArrayList();
  while (rs.next()) {
   IList.add(rs.getString(1));
  }
  for (int i = 0; i < IList.size(); i++) {
   System.out.println(IList.get(i));
  }
  return IList;

 }

}

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger