• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

how to populate value in combo box

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!

I m developing an JSP application, can someone please help me to retrieve values from a (SQL) database and enable those retrieved values to populate the comboBox component of my form. In addition, if a user selects a certain value through populated comboBox,that also insert into database pls. give an example of code that would some how solve my problem. please help me as soon as possible!!!

thank you!!!
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just search it out with "populate combo" you'll get lots of material on this forum...
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've just posted an example project that does this:
http://simple.souther.us/not-so-simple.html

It's written with an MVC architecture but it should give you the basic idea.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the simplest way...
My sample code..


buf1.append("<select name=\"LocationB\">");
buf1.append("<option value=\"\">-Location-</option>");
db.setResultSet("SELECT distinct CLEAR_LOCATION FROM PMS.VW_BILL_PROJECTREQUEST order by CLEAR_LOCATION");
rs = db.getResultSet();
while(rs.next()) {
buf1.append("<option value=\"" + rs.getString("CLEAR_LOCATION").trim() + "\">" + rs.getString("CLEAR_LOCATION").trim() + "</option>");
}
buf1.append("</select>");
tLocB = buf1.toString();
buf1.delete(0, buf1.length());
rs = null;


and down in in the jsp replace the select box portion with ....
<%= tLocB%>
 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
thanks a lot for ur kind help ,but i need some code in java so it is easy to understand .
actualy i want to populate value from database into combobox,
for ex-:
in student form there is a column qualification
so how can populate value from database
thank you!!!
 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
thanks a lot for ur kind help ,but i need some code in java so it is easy to understand .
actualy i want to populate value from database into combobox,
for ex-:
in student form there is a column qualification
so how can populate value from database
thank you!!!
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Do you want the java code which is embedded in JSP to populate a ComboBox.
 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
yes i want the java code which is embedded in JSP to populate a ComboBox
please please it is so importent for me.
 
Raghuraman Muthuswamy
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sarika,
The code uses MS Access as database for JDBC. This is just a sample code. But the logic will be same for all databases.

<html>
<head>
<title>Combo Box Data from Database</title>
</head>
<%@ page import="java.sql.*"%>

<body>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc dbc SN_Name";
Connection con = DriverManager.getConnection(url);
Statement s = con.createStatement();

ResultSet re = s.executeQuery("select * from Table_Name");
%>
<h2>Username from Database Modified: </h2>
<select>
<%
while(re.next())
{
String un=re.getString(Field_Name);
%>
<option value="<%= un%>"><%= un%></option>
<%
}
%>
</select>

</body>
</html>
reply
    Bookmark Topic Watch Topic
  • New Topic