Share on Google+Share on Google+

Ramakrishna
HTML
1 Answer(s)      8 years ago
Posted in : JDBC

Ads

View Answers

May 6, 2009 at 9:49 AM


Hi Friend,

To do this code we have created two tables city(id, cityname,countryid) and country(countryid,country) . Now when we select the country from the first
combobox it will fetch the name of the cities according to the country Id.
Here is the JSP page code as follows :

<%@ page language="java" %>
<%@ page import="java.sql.*" %>

<%!
Connection conn = null;
ResultSet rs =null;
Statement st=null;
String query="";
int cid;

%>

<%
if(request.getParameter("cid")!=null){
cid=Integer.parseInt(request.getParameter("cid"));
}else {
cid=0;
}
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
st = conn.createStatement();
rs = st.executeQuery("select * from country");
%>
<html>
<head>
<script type="text/javascript">

function selectCity(){
var cid=document.getElementById("country").selectedIndex;
alert(cid);
window.location.replace("http://localhost:8080/showImage/countrylist.jsp?cid="+cid);
}

</script>
</head>
<body>
<select id="country" onchange="selectCity(this)">
<option value="0">--Please Select--</option>
<% while(rs.next()){ %>
<option value='<%=rs.getInt("id")%>'><%=rs.getString("countryname")%></option>
<%}%>
</select>
<%
rs = st.executeQuery("select * from city where countryid='"+cid+"'");
%>
<select>
<option value="0">--Please Select--</option>
<% while(rs.next()){ %>
<option value='<%=rs.getInt("id")%>'><%=rs.getString("name")%></option>
<%}%>
</select>
</body>
</html>

Thanks
RoseIndia Team









Related Tutorials/Questions & Answers:
HTML
HTML  What is Semantic HTML? What are the reasons for validating a HTML
HTML
HTML  What is Semantic HTML? What are the reasons for validating a HTML
Advertisements
HTML
HTML  What is SPAN in HTML
html
html  How to add the calendar in html code
HTML
HTML  What is BODY in HTML document
HTML
HTML  What is HTML? What is a Hypertext link
HTML
HTML  What is HTML? What is a Hypertext link
html
html  diffrence between html and xml
Html
Html  What is HTML? What is a Hypertext link
html
add a header in the html page  what we can do to add a header in the html page
HTML
HTML  how can we give the unlimited size in the html
html
html  what we can do to add a header in the html page
html
html  what we can do to add a header in the html page
html
html  i want a registration page in html with good background
html
html  how to convert html page into jsp page
HTML
HTML  What is a tag? How can we use MARQUEE in HTML
HTML
HTML  How do we specify page breaks in HTML
HTML
HTML  Hi, What is the full form of HTML? Thanks   Hi, The HTML stands for HyperText Markup Language. HTML is used to create webpage for world wide web. Web pages are accessed by web browsers and then shown
html
html  sir i am new to eclipse and i am created a html program and also tomcat is running successfully in side the eclipse.but now how i deploy that html program in the eclipse
HTML
HTML  How do we create a link? What are the three types of form tags in HTML
html
Adding Header in HTML  what we can do to add a header in the html page
html
html  how we can give the form actions in html after register button in the login page
html
html  Can we Access database through html page and how,if not then why
html
html  For what is used HTML?   Using HTML we can create a Web Page which can be viewed through a Web Browser over Internet. HTML describes... or the End Tag is defined as </> . The whole HTML document is enclosed
Html
Html  in the web page if judge select the age and category then automatically under that conditions the details will be display in the form of grid give me that code in html and java
html
html   write a html program to print "HELLO WORD"in red coaler font size 12 and italic stile   Here is a html code that display the message "Hello World" in red font with size 12 and in italics. <html> <
Html
Html  i am select the dateofbirth through the html browser.but it can not save into the sql server 2008 database.any special code required to store the date in database by using java servlets
HTML
HTML  how can we design the gird form view in html i want the following fields in the grid form The fields are Name of the candidate,Title... me the coding for this in html
HTML
HTML  in html how can we can upload the file <tr> <td><strong>Video of the work:</strong> <td><b>... the file give me the code for this in html and java
HTML
HTML  I have created an info.html file for the applet.The class file is located in a directory different from the HTML file.The info.html file I have created is below. <HTML> <HEAD> <BODY> <APPLET Code
Html
:48:44 PM Author : SAMSUNG --%> <[email protected] contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01...; <head> <meta http-equiv="Content-Type" content="text/html
Tutorials   
Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu

Ads

 
Advertisement null

Ads