473,388 Members | 1,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

how I can fetch data from mysql database to show in a form's drop down box with jsp

there is one registration form where using dropdown box i select one country and it save into mysql database.
now i want to fetch that value of mysql database table into edit profile form where i can edit it.
plz help me with jsp coding ..
best regard
vishal prada
Mar 2 '12 #1
4 4626
r035198x
13,262 8TB
You retrieve the value using your data access classes and then when you build the options for the edit screen you set the selected flag

If you are hard coding country options on the page you would use
Expand|Select|Wrap|Line Numbers
  1. <c:choose>
  2.    <c:when test="${databaseValue == 1}">
  3.         <option value="1" selected> 
  4.           <c:out value="India" />
  5.         </option>
  6.     </c:when>
  7.    <c:otherwise>
  8.        <option value="1"> 
  9.           <c:out value="India" />
  10.         </option> 
  11.    </c:otherwise>
  12. </c:choose>
With hard coding you would do this for every one of your options.

If you took earlier advise and put all those countries into a List then your code is much simpler and shorter, just something like
Expand|Select|Wrap|Line Numbers
  1. <select name="countryId"> 
  2.    <c:forEach var="country" items="${countries}" >
  3.    <c:choose>
  4.    <c:when test="${databaseValue == country.id}">
  5.         <option value="${country.id} selected> 
  6.          <c:out value="${country.name}" />
  7.         </option>
  8.     </c:when>
  9.    <c:otherwise>
  10.       <option value="${country.id}">
  11.           <c:out value="${country.name}" />
  12.         </option> 
  13.    </c:otherwise>
  14.   </c:choose>
  15.    </c:forEach>
  16. </select>
  17.  
  18.  
  19.  
and it would cover all countries.
Mar 2 '12 #2
tell me one thing ur given code is in jsp or jsf ?
Mar 2 '12 #3
r035198x
13,262 8TB
It's JSTL which you should use in JSPs or JSF. It helps keep Java code away from JSPs.
Mar 2 '12 #4
can u give me one demo of change password from database with jsp code.
Mar 2 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Joey Liang via DotNetMonster.com | last post by:
Hi all, I am new to ASP.NET, i have met some problems in binding data from a table of database to a dropdown list control. Anyone knows how to do it?if possible can rougly write the codes or any...
5
by: ashok893 | last post by:
I'm using two drop down list ina form. I have generated the first drop down list from MySQL database. When i select an option from first drop down list, i have to generate second drop down list...
11
by: saurabhbpl | last post by:
hi, i have a html drop down menus and i want to conver it into dynamically means that menu show data from database.how can i fetch data from database for using menus and sub menus using php and...
2
by: stewy | last post by:
I'm about to create a form that will be using a sql query array that i'd like to put into drop down list.... 28 times in one page. Is there an alternative to building the same 28 sql queries? eg,...
2
by: hazelnut2705 | last post by:
Hi there.. how to fetch data from database and then display in title bar? <html <?php echo HTML_PARAMS; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo...
2
by: leeperman | last post by:
In Dreaweaver I cannot filter my database results to display only specific data that is retrieved from mulptile drop down list on my search page. The drop down list selections are posted to my...
26
by: agarwalsrushti | last post by:
Hello, I ve created a php form for user registration in which have also used the drop down boxes. I want that data in the drop down box should be taken from mysql database. The data in...
3
by: ghjk | last post by:
i have two drop down boxes and when user select District from 1st drop down box , the cityis in that district should load to the second drop down. My code is below. But it is not working. Please...
9
by: andersond | last post by:
I have a web application that allows retail insurance agents to get quotes 24/7. There is a data file for quotes, a data file for vehicles, a data file for drivers and a data file for...
3
by: bharathk27 | last post by:
i have an datetimepicker and combobox in my winform. i have to fetch data in combobox according to date selected in date time picker.. i wrote this code in combobox, but it dosen't work. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.