473,508 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

jsp and jdbc

58 New Member
Hi All,
I written a code for one scenario,
let me explain that...

i created a jsp page with two combo boxes.
in first combo box i took values from data base using jdbc imagine
those values are
India
America

if i select India in first combo box it should show the states of india in second combo box...
if i select America it should show states of America.

i written code using script for that selection like
Expand|Select|Wrap|Line Numbers
  1.  if(d=="India")
  2. {
  3. }
  4.  
here d is selected value in first combo box.
like this i put conditions for those two values i.e India,America..

but if two more countries and also their states will add in the future then my code will not work. then how can i solve it.

anybody can help me
i want to update it automatically
Apr 4 '07 #1
2 2358
itsraghz
127 New Member
Hi All,
I written a code for one scenario,
let me explain that...

i created a jsp page with two combo boxes.
in first combo box i took values from data base using jdbc imagine
those values are
India
America

if i select India in first combo box it should show the states of india in second combo box...
if i select America it should show states of America.

i written code using script for that selection like
Expand|Select|Wrap|Line Numbers
  1. if(d=="India")
  2. {
  3. }
  4.  
here d is selected value in first combo box.
like this i put conditions for those two values i.e India,America..

but if two more countries and also their states will add in the future then my code will not work. then how can i solve it.

anybody can help me
i want to update it automatically
Try to get the values from database at one shot and store them into an Array. Array here is the JavaScript Array.

Continue for both the Combo boxes.

In the onChange event of the comboboxes, get the selectedIndex value of the combo box and proceed with the appropriate value in the second box.


Hope this helps....
Apr 4 '07 #2
r035198x
13,262 MVP
Hi All,
I written a code for one scenario,
let me explain that...

i created a jsp page with two combo boxes.
in first combo box i took values from data base using jdbc imagine
those values are
India
America

if i select India in first combo box it should show the states of india in second combo box...
if i select America it should show states of America.

i written code using script for that selection like
Expand|Select|Wrap|Line Numbers
  1. if(d=="India")
  2. {
  3. }
  4.  
here d is selected value in first combo box.
like this i put conditions for those two values i.e India,America..

but if two more countries and also their states will add in the future then my code will not work. then how can i solve it.

anybody can help me
i want to update it automatically
Here is a brute force approach using javascript:


Put a hidden select on the page. On load of the page, populate this select with all the Countries and States that you have in the database in a systematic manner. An example is

XXAmerica
city1
city2
.
.
.
cityn
XXIndia
city1
city2
.
.
.
cityn

So that you have a label (XX in this case) and a country followed by all the cities of that country for all the countries that you have in the database.

This is your dataselect and you don't show this on the page (style = "display:none"). Call this, say dataSelect.

Then you have your two drop downs. One for countries and the other for cities.

You load the countries drop down with all the countries you have and put an onchange on it. So onchange of the countries dropdown, you call a method which does the following

take the selected country, add the label (XX for this example) and search for this value in the dataselect which you can access using javascript.
Once you find the entry there, retrieve all the values from the select that follow after it until you reach a value that starts with the label (XX). As you retrieve each value, add them as options to the cities select.

The code for this would look something like

[HTML]
function populateCities(form) {
var all = form.dataSelect.options.length;
form.citiesSelect.options.length = 0; //clear all cities
var country = form.countries.options[form.countries.selectedIndex].value;//selected country
var end = false;
var temp = 0;
for (i = 0;(i < all) && (end == false); i++) {
var current = form.dataSelect.options[i].value;
if(current == "XX" + country ) {//find country in dataSelect
index = i + 1;
var cur = form.dataSelect.options[index].value ;
var cursub = cur.substring(0, 2);
while(cursub != "XX") {
var nextValue = form.dataSelect.options[index].value;
var nextText = form.dataSelect.options[index].text;
form.citiesSelect.options[temp++] = new Option(nextText, nextValue);
index = index + 1;
cur = form.dataSelect.options[index].value;
cursub = cur.substring(0, cuntry.length);
}
end = true;
}
}
}
[/HTML]

As you can see this is purely a Javascript problem so I'll copy it there.
Apr 4 '07 #3

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

Similar topics

0
4472
by: JShurmatz | last post by:
If anyone can shed some light on this problem I would greatly appreciate it. I am unsuccessfully trying to use a database connnection retrieved from a pool configured using Java System Web...
0
2255
by: Nils Valentin | last post by:
Hi MySQL Fans ;-), Is it possible that the 3.08 series allows to connect to 4.0.14 versions but not to the 4.1 alpha-versions ? I get belows error when tryig to connect from DbVisualizer which...
0
4231
by: Robert Mazur | last post by:
MySQL 5.0 alpha (binary install) on Solaris 9 -or- RedHat 8.0 mysql-connector-java-3.0.8-stable ----------------------- Is there something different going on with JDBC and the alpha version...
0
3066
by: Bing | last post by:
Hi, I am configuring the same DB2 v8.1 JDBC universal driver (db2jcc.jar and db2jcc_license_cisuz.jar) from DB2 SP5 fix pack under WSAD 5.1.x environment and WebSphere application Server 5.0.2...
0
3217
by: Raquel | last post by:
UDB PE 8.1 on Win XP. Per the manual: DB2 JDBC traces always begin with a header that lists important system information such as key environment variable settings, the JDK or JRE level, the...
1
8986
by: Praveen | last post by:
Hi, I have installed WebSphere Portal on AIX and connected to DB2 on a remote machine, Getting the followin errors when trying to get the values from database thru applications installed on...
1
8759
by: rpm45tech | last post by:
Hi everyone. I'm deveolping in Java with DB2 running on Win XP and everything was working ok but then I installed Vista Ultimate and the application stopped working. This is the exception showed: ...
2
4528
by: bevis | last post by:
I'm new to sql server and mysql but this seems like it should be a pretty straight forward jdbc connection. But I have spent almost 2 days just trying to get a jdbc connection. Please help if you...
3
22827
by: Anoop | last post by:
Is it true that there are no type 4 jdbc drivers to connect to a DB2 server v7.1? The DB2 server is hosted on ACF2 (OS/390). We would be connecting from windows and solaris boxes. If it is true,...
0
604
by: Jim Kennedy | last post by:
ALL DDL does a commit. Hence Drop Table movies; issues a commit. True you don't issue a commit and the driver does not issue a commit, but the server does for all DDL. That is probably where...
0
7323
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
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.