473,664 Members | 2,995 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 2373
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.citiesSele ct.options.leng th = 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.citiesSele ct.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
4487
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 Server 6.1 with the SQL Server 2000 JDBC Driver. The background: 1. I have downloaded the SQL Server 2000 JDBC Driver and installed it on the web server.
0
2261
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 was working fine until a while ago. I haven't watched it recently, and haven't changed anything I am aware off right now. After I realized the problem I tried many 3.08 versions with the same symptom. Watch were it says "Unknown system variable...
0
4239
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 of MySQL 5.0? When trying to connect I am getting: ** BEGIN NESTED EXCEPTION **
0
3080
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 on Windows 2000 machines. I configured a connection pool data source using type 4 for a local test environment in WSAD 5.1.x, and a connection pool data source on the WebSphere Server too. Both data sources are accessing the same database.
0
3260
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 DB2 JDBC driver level, and the DB2 build level. For example: 1 ======================================================== 2 | Trace beginning on 2002-1-28 7:21:0.19
1
9014
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 Portal. Any Help Appreciated. Thanks in advance. Praveen Singh
1
8785
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: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'COM.ibm.db2.jdbc.app.DB2Driver' for connect URL...
2
4546
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 can. I'm using Eclipse 3.2.2 and I have installed mysql-connector-java-5.0.6-bin.jar. I am trying to connect to SQL Enterprise Manager version 8.0 innstall on a Windows 2003 Server Enterprise Edition. I have been able to successfully test...
3
22836
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, what are my options? Will I have to install db2 connect on every client machine that needs to connect to the DB2 servers? Is the DB2 Connect freely available or will we have to purchase it? I have also read on this group that we can install DB2...
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 your commit is coming from. Jim -- Replace part of the email address: kennedy-down_with_spammers@attbi.com with family. Remove the negative part, keep the minus sign. You can figure it out.
0
8437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8861
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7375
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5660
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4185
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2003
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.